Pope Francis wrapped up a triumphant first overseas trip as pontiff with a Sunday mass on Copacabana beach attended by three million worshippers, according to Rio authorities' estimates.

In the evangelical, simple and radical style that has characterised his week-long visit to Brazil, Francis made an appeal to pilgrims to return to their home countries and revitalise the Catholic church.

He urged followers to be more active in their faith by reach out to "to the fringes of society, even to those who seem farthest away, most indifferent".

"The church needs you, your enthusiasm, your creativity and the joy that is so characteristic of you," he told the vast throng, hundreds of thousands of whom had slept overnight on the 4km-long beach.

Underscoring the influence of the church in Latin America, his congregation included the presidents of Brazil, Argentina, Bolivia and Suriname, as well as the vice presidents of Uruguay and Panama and a host of other dignitaries.

Authorities said the crowd for the final mass of the World Youth Day Catholic festival had swollen to more than 3 million people over the weekend. Many who camped on the beach overnight said they had trouble sleeping owing to the cold and the noise of the waves and happy pilgrims singing until the early morning.

"I'm very tired but happy. It was good fun," said Paul Mitchell, from Sydney, who slept on the sand and went for a swim before the mass began. "It was amazing to see other people's faces. People here are so alive and filled with the love of God. We could learn from that, especially the church in Australia."

Waving their hands, singing and praying together, the huge crowd joined in an often rapturous shared worship.

Sister Mary Herrera giggled when asked how it feels to sleep with three million people.

"This is what I call a revolution of love," said the nun, who teaches in poor communities and drug rehabilitation centres in Argentina.

The festival has brought a population bigger than the combined residents of Manchester and Birmingham into Copacabana for open-air events relayed along the beach by more than a dozen giant screens.

In the coming days, the migration will reverse. Many of those who will join the exodus say they will take back an activist message from the pope's sermons.

Lucas Robles, a 20-year-old from Peru."It has been fantastic. Much bigger and better than carnival. This also has a real purpose."

During his visit, the pope has consistently struck a politically radical tone. He expressed support for protesters who joined the huge demonstrations across Brazil last month.

"The young people in the street are the ones who want to be actors of change. Please don't let others be actors of change," the Argentine pontiff said during a Saturday night vigil. "I ask you to be actors of change, keep overcoming apathy and offering a Christian response to the social and political concerns taking place in different parts of the world."

The 76-year-old added visits to a favela slum, a drug rehabilitation clinic and a prison to his schedule to underscore his belief that Catholics need to reach out to the poor and underprivileged on the periphery of society.

He has also called on the church to reflect on why it has lost so many former followers to secularism and Pentecostal faiths in recent years.

Compared to his bookish predecessor, Francis has adopted a populist style, using simple language and references to popular culture.

An avid football fan, he told his audience: "Jesus offers us something bigger than the World Cup!"

But he has been uncompromising on contentious issues that separate the church from much of modern society. On Sunday, he invited a couple with an anencephalic baby to be blessed. The father was wearing a "Stop abortion" T-shirt.

For many in Latin America, this will recall a recent controversy in El Salvador where a young woman pleaded with the authorities to let her terminate her pregnancy with an anencephalic foetus.

Hundreds of people joined protests against the Catholic church on Saturday evening with a "slutwalk" by women – and a few men – in skimpy clothing, bearing signs declaring "Get your cross out of my uterus!" and banners criticising the pope's opposition to same-sex marriage.

Earlier demonstrations criticised local politicians, who have reportedly spent more than $50m (£32.5m) of public funds to host the event.

Overall, however, Vatican officials have declared the festival – which they say has attracted more than double the participants of any previous World Youth Day – as a success.

The hosts, however, face renewed questions about their organisational abilities.

This weekend's vigil and mass were supposed to have been held at a custom site on the outskirts of the city, but the venue was switched at the last moment because the field was waterlogged.

Traffic and public transport problems have also plagued the event and raised doubts about the upcoming World Cup and Olympics.