HAVANA - Pope Francis celebrated Mass in Havana's Revolution Square on Sunday and met with former leader Fidel Castro but warned Cubans against the dangers of ideology as their country enters a new era of closer ties with the United States.

Tens of thousands of people were in the square where Cubans celebrate May Day beneath massive portraits of revolutionary leaders Ernesto "Che" Guevara and Camilo Cienfuegos built into the facades of state buildings.

To welcome the pope, who helped bring about the recent rapprochement between Cuba and the United States, a similarly giant poster of Jesus Christ was hung nearby. The 78-year-old Argentine pontiff read a mostly religious homily but sprinkled it with criticism of "elitism" and ideology.

"Service is never ideological for we do not serve ideas, we serve people," he said in his homily of the Mass, which was attended by President Raul Castro and top members of the communist government.

Francis later met with Fidel Castro, who led Cuba's 1959 revolution and then built a one-party state that improved health and education services for Cubans but also limits democratic freedoms and represses dissent.

Cuban police kept some dissidents from attending the pope's Mass on Sunday morning and pounced on others apparently attempting to hand out flyers near the plaza.

In what government opponents could see as a criticism of party bureaucracy, he said Jesus' apostles foolishly argued about their rank and the pope compared it to "those who climb the ladder most quickly to take the jobs which carry certain benefits".

Francis also appeared to appeal to Cubans to look after each other as the country faces social changes and economic openings.

He said they should continue to be "at the service of the frailty of your brothers and sisters" and "not neglect them for plans which can be seductive, but are unconcerned about the face of the person beside you".

At the end of the Mass, the pope appealed to Colombia's government and Marxist FARC guerrillas to ensure that nearly three years of peace talks in Cuba are successful in order to end their "long night" of war.

Many in the crowd waited for hours in the tropical heat, eager to hear the first Latin American pope speak to them in Spanish, their common language.

"Francis has come to bless this new union between Cuba and the United States," said Enrique Mesa, a 32-year-old tourism worker.

Between 30-40 dissidents were detained to stop them attending papal events, a dissident human rights group said.

Security agents wrestled two men and a woman to the ground at the edge of Revolution Square, then led them off, after they started shouting and tried to hand out flyers, a Reuters witness said.

Arriving on Saturday, Francis exhorted Cuba and the United States to deepen their detente, and encouraged Cuba to grant more freedom to the Roman Catholic Church, which has re-emerged as a powerful force after suffering decades of repression.

"His visit is cause for hope in our aspirations for improvement," said biologist Benito Espinoza, 41, at Revolution Square. "We are an optimistic people, but we have suffered for many years."

Francis waved and greeted Cubans as he arrived at the Mass, delighting one family when he picked up and kissed a four-year-old girl Karen Correoso. "It's a historic moment for her and for us. He blessed her," said the girl's aunt, Maria Teresa Gonzalez, 64, from a church in Matanzas city.

Many Cubans appreciate the pope for his role in the secret talks that led to last December's breakthrough with Washington, when Castro and US President Barack Obama vowed to normalize relations and end half a century of Cold War-era animosity.

Francis will fly from Cuba to Washington on Tuesday for meetings with Obama and addresses at the US Congress and United Nations.

Cuba will welcome any papal condemnation of the US economic embargo, which persists despite Obama's policy change as only the US Congress can lift it. The Republican leadership in Congress has defied Obama's calls to do so.

But Castro's government will also be sensitive to any criticism of its one-party political system or repression of dissidents.

Elizardo Sanchez, head of the Cuban Commission of Human Rights and National Reconciliation, said most of the 30-40 opposition activists rounded up were in Santa Clara and Havana.

Among them were three dissidents whose detention kept them from approaching the papal residence on Saturday night, where they hoped to see the pope. They said they had been invited but a Vatican spokesman said he was not aware of any invitation to any group.