Pope Benedict urged 1.5 million young Catholics at a Sunday mass in an aerodrome to spread the gospel to others on the last day of a four-day visit to the Spanish capital marked by violent protests.

Hundreds of Spaniards, including priests, took to the streets earlier in the week to object to the cost of hosting a private religious event at a time of spending cuts. A march ended in clashes with police on Wednesday night.

The pope told pilgrims from 193 countries on Sunday that they have been given the extraordinary task of being missionaries of Christ in other countries filled with young people looking for better values.

We cannot encounter Christ and not want to make him known to others. So do not keep Christ to yourselves! Share with others the joy of your faith, he said in a sermon read from a white throne under a stylized golden tree.

Hundreds of thousands of pilgrims, bearing flags from their countries and wearing hats to protect themselves from the sun, prayed, applauded and cheered during the service.

A choir and orchestra dressed in blue and adorned with white lilies accompanied the mass, while Spain's King Juan Carlos and Queen Sofia looked on.

When you're at home, you just think you're alone in your faith, but when you pray with over a million people it just changes things, said Katharina Eisen, 18, from Germany.

PRAYER VIGIL

Pilgrims had been at the Cuatro Vientos aerodrome since Saturday evening, when Benedict led a prayer vigil.

Madrid emergency services said it had treated more than 2,500 people during the vigil -- a record for a programed event -- as sweltering heat was followed by an electric storm on Saturday night.

Saturday's heavy rain prevented Benedict from reading a prepared speech in which he had made a veiled criticism of Spain's legalization of gay marriages and abortion.

Spain became the third country in the world to legalize gay marriage in 2005 and Prime Minister Jose Luis Rodriguez Zapatero made it easier for women to terminate unwanted pregnancies in 2010.

Critics put the cost of hosting the visit at around 100 million euros, mostly due to the heavy security which has surrounded the pontiff, with roads cut off to traffic and thousands of police on the streets.

The hoards of young people attending the events were put up in state schools and given subsidized public transport tickets at a time when the cost of Madrid metro and bus tickets are rising by 50 percent for residents.

Organizers said the event cost the taxpayers nothing due to corporate sponsorship.

The next World Catholic Youth Day will be in Rio de Janeiro, Brazil in 2013.