Pope Benedict XVI denounced the profit-at-all-cost mentality that he says is behind Europe’s economic crisis as he arrived in hard-hit Spain on Thursday, adding that morals and ethics must play a greater role in formulating economic policy in the future.

Benedict made the comments as he traveled to Madrid for World Youth Day, a weeklong Catholic festival that is taking place against a backdrop of the European debt crisis and social unrest among the young that exploded recently in rioting across Britain.

Benedict said the crisis and sense of desperation among young people proved that ethics have been increasingly left out of formulating economic policy at local and international levels.

“The economy doesn’t function with market self-regulation but needs an ethical reason to work for mankind,” he told reporters traveling on the papal plane. “Man must be at the center of the economy, and the economy cannot be measured only by maximization of profit but rather according to the common good.”

He said the crisis shows that a moral dimension isn’t “exterior” to economic problems but “interior and fundamental.”

Benedict explored the theme more fully in his 2009 encyclical “Charity in Truth,” in which he called for a new world financial order guided by ethics, dignity and a search for the common good.

On Wednesday night, about 5,000 people opposed to the pope’s visit marched peacefully to Madrid’s central Puerta del Sol plaza, which has been the center of Spain’s anti-establishment protests since May. A smaller number of protesters then clashed with riot police. Police said eight demonstrators were arrested and 11 people were injured. A protest march against the pope last year in London drew some 10,000 people, the largest such anti-pope demonstration in recent times.

“People were going really crazy, but at the same time, God wants all of us to be here, and I know that he’ll, like, protect us all while we’re here,” said Holly Springfield, a 17-year-old American who saw the protest.

But Benedict arrived in Madrid on Thursday to a boisterous welcome from young people. Their faces painted the colors of the Spanish flag, they chanted, “These are the pope’s young people!” A cordon of youngsters decked out in faux Swiss Guard uniforms greeted Benedict on the tarmac at Madrid’s Barajas airport, along with King Juan Carlos and Queen Sofia.

Socialist Prime Minister Jose Luis Rodriguez Zapatero and conservative opposition leader Mariano Rajoy, the man forecast to take power in November elections, also were present.

In a speech delivered on the tarmac in Spanish, Benedict referred to the precariousness many young people see in their future. Unemployment in Spain is nearly 21 percent and is the highest in the euro zone.

“Many young people look worriedly to the future as they search for work either because they have lost their job or because the one they have is precarious or uncertain,” Benedict said. He urged young people to keep fast in their faith.

The king also referred to the sense of hopelessness many young people feel, saying today’s youths are “frustrated by the lack of personal and work possibilities and rebel against the serious problems facing the world today.”

As Benedict was being driven from the airport to the Vatican Embassy through one of the capital’s most affluent neighborhoods, streets and bridges were filled with youths waving flags, throwing white and yellow balloons — the Vatican’s colors — and cheering. The popemobile was surrounded by security cars and motorcycles.

The trip was Benedict’s third to Spain, cementing the country’s reputation as ground zero in his campaign to reinvigorate the faith in European countries where Catholicism has fallen by the wayside. Laws passed under Zapatero allowing gay marriage, fast-track divorce and easier abortions have deeply angered the Vatican, which sees the once staunchly Catholic country as a battleground for the future of the faithful in Europe.

Many Spaniards have balked at the cost of the visit at a time of economic difficulty, citing the fact that pilgrims are getting deeply discounted subway and bus tickets while such prices for everyone else went up 50 percent this month, to $1.50.

Vatican Radio responded to the critics Thursday, noting that the $72 million tab for staging World Youth Day is being paid for by the participants themselves, some private donors and the church. Critics say the organizers’ estimate for the price tag doesn’t include security costs and is a fraction of the total price tag for Spaniards.

Organizers expect a million or more young people from 193 countries to attend the festival.

The main events are a prayer vigil with the 84-year-old pope and outdoor sleepover for pilgrims Saturday night at a sprawling air base, and Mass there the next morning.

— Associated Press