Pope Benedict XVI strongly defended the traditional family — based on marriage between a man and a woman — during a visit to Spain on Saturday, taking on a Socialist government that has introduced liberal reforms such as gay marriage and fast-track divorce in this former bastion of the Roman Catholic Church.

As Prime Minister Jose Luis Rodriguez Zapatero stood nearby, staring straight ahead, Benedict called the family "a unique institution in God's plan."

"I wish to set forth the central role, for the Church and for society, proper to the family based on marriage," the German-born pope said, speaking under a canopy protecting him from the blistering Mediterranean sun.

CountryWatch: Spain

Zapatero was booed by a small group of neighborhood residents when he, accompanied by his wife, arrived at the archbishop's residence for a face-to-face meeting with Benedict. Neither the Vatican nor the prime minister's office issued any immediate comment on the 30-minute talks.

Relations between the government and the Holy See have been strained, and the plans for the meeting — held on the pope's territory — were confirmed only a few weeks before the trip.

Benedict was making the third foreign trip of his papacy. He came to Spain for only 26 hours to address an international meeting on the family, an institution the Vatican warns is increasingly threatened by such liberal reforms as gay marriage, which was recently legalized in Spain, as well as in the Netherlands, Belgium and Canada.

In a city festooned with flags and balloons bearing the yellow and white colors of the Vatican and brimming with pilgrims from around the world, the pontiff also prayed for 42 people killed in a Valencia subway derailment on Monday — a tragedy that added a tinge of sadness to his first visit here as leader of the Roman Catholic Church.

"We ask God's comfort for those who remain and those who left us," the pope said, speaking in clear Spanish outside the ill-fated station named for nearby Jesus Street, where he laid a wreath of white roses. The crowd hushed to let him speak.

Many Spaniards have drifted away from the Church in the three decades since the fall of the Gen. Francisco Franco dictatorship, under which it enjoyed special privileges. But tens of thousands turned out to greet Benedict when he arrived in Spain's third-largest city and organizers expected as many as 1.5 million people to attend Sunday's papal Mass.

Benedict, visiting Valencia's 17th century cathedral, told his bishops he was aware of the secular drift in a country with "deep Christian roots" and urged them to "keep alive and vigorous this spirit, which has accompanied the life of Spaniards throughout their history."

Benedict addressed gay marriage before even getting off the plane that flew him in from Rome.

Asked about the role of gay marriage in society, the pope told reporters: "According to human nature, it is man and woman who are made for each other and to give humanity a future."

"The Church can't accept certain things," he said. "At the same time, it wants to help people and respect them."

King Juan Carlos, Queen Sofia as well as Zapatero welcomed the pope on his arrival and a military band played the national anthems of Spain and the Vatican as hundreds of faithful endured sweltering, muggy weather to see the pontiff.

Some in the crowd booed loudly when Zapatero arrived.

In addition to approving gay marriage, Zapatero's government has made it easier for Spaniards to divorce and halted a plan by a previous, conservative government to make religion classes mandatory in public schools.

Spain has passed from being a bastion of Roman Catholicism to a predominantly lay society in less than a generation. Statistics show that while 80 percent of Spaniards still call themselves Catholics only 42 percent believe in God and 20 percent go to Mass.

Maria Luisa Galdon, a 54-year-old housewife with three daughters, said Spain needs the visit because families here are in trouble. "What's missing is love, understanding and education," she said.

She thinks the pope should give Zapatero a message to improve relations with the church and give it more support. "I think he will do it politely and necessarily," Galdon said.

Jose Ramon Gonzalvez, a 38-year-old civil servant who lives in the neighborhood of the subway crash, called the pope's stopover at the metro station "a very important declaration of his support for all of us and an expression of his love."

The Vatican seemed irritated that Zapatero was not planning to attend a papal Mass on Sunday.

"The Holy See doesn't invite leaders to Mass," said papal spokesman Joaquin Navarro-Valls. But he noted that such left-wing stalwarts as Fidel Castro of Cuba and former Nicaraguan President Daniel Ortega have attended papal masses.

Thousands of police were providing security, including sharpshooters atop building and AWACS planes on loan from NATO patrolling the skies.