Pope Francis
Pope Francis in Brazil

Pope Francis addressed an estimated three million Catholic pilgrims on the shores of Rio's Copacabana beach on Sunday, bringing to an end his five-day visit to Brazil.

The pontiff closed what was the biggest Catholic youth festival in history with a mass, marking the end of his first foreign trip since he was appointed pope in March.

Many of the pilgrims had slept on the beach after hearing the pope address an all-night vigil, pitching tents and staying on all day to attend the Mass.

The two-and-a-half mile stretch of beach has been dubbed the "Popacabana".

Speaking the night before, the pontiff had urged the pilgrims not to be "part-time Christians", and described the world's youth as its only legitimate "actors of change".

Speaking on a huge stage that included a mock church structure, Pope Francis referred to the street protests which have been taking place in Brazil for more than a 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," he told the crowd at the vigil.

"Keep overcoming apathy and offering a Christian response to the social and political concerns taking place in different parts of the world."

At a mass earlier, the Argentine pontiff, 76, renewed his call for priests to go out of their cloistered parishes and bring the message of the Gospel to the world's slums.

"It is in the favelas... that we must go to seek and serve Christ," he told thousands of bishops and priests from around the world at a mass at the city's St Sebastian Cathedral.

"We cannot keep ourselves shut up in parishes, in our communities, when so many people are waiting for the Gospel," he said.

He called on Brazil's elite to use "constructive dialogue" to mediate between maintaining the status quo and fending off violent upheaval.

"Constructive dialogue... (is) essential for facing the present moment," Francis said. "Between selfish indifference and violent protest there is always another possible option: that of dialogue."

The Vatican has been alarmed by the growing strength of Evangelical Protestant churches in Brazil, as well as the spread of secularism.

Pope Francis had called for a "church able to enter dialogue with those disciples who, having left Jerusalem behind, are wandering aimlessly, alone, with their own disappointment - disillusioned by a Christianity now considered barren, fruitless soil".

Wearing a white overcoat because of the cold, rainy weather, Francis waved at crowds from his open-sided Popemobile, blessing the faithful lining the avenue along the seafront.