By Philip Pullella and Anthony Boadle
RIO DE JANEIRO (Reuters) - Pope Francis left Brazil on Sunday with Rio still pulsating with excitement after a historic beachfront Mass for more than 3 million people in which he challenged young people to build a new world based on tolerance and love.
Rio's famed Copacabana beach, usually the venue for scantily-clad sun-seekers and revelry, became a massive Catholic campground for the closing event of a world youth festival.
The festive crowd included pilgrims from 170 nations who spent the night on the beach and locals who poured out of homes and buses to see the Argentine pope on his first trip abroad since his election in March.
"Through your joyful witness and service, help to build a civilization of love. Show, by your life, that it is worth giving your time and talents to attain high ideals," Francis said at the Rio airport before he departed for Rome.
Pleased Vatican officials said the massive attendance showed the vitality of the Catholic Church, which is hoping that the charismatic pope will re-energize the institution at a time when rival denominations, secularism and distaste over sexual and financial scandals has lost it followers.
Aerial television footage showed the sand and sidewalks of Copacabana blanketed with people for several kilometers along the crescent-shaped shoreline.
The throng of people, many in the green and yellow Brazilian colors, gave Francis the kind of ecstatic welcome that he has received all through his trip to his home continent.
They shouted and sang as he was driven through the crowd in an open-sided popemobile, stopping often to kiss babies offered to him by their mothers on the shoreline most famous for its bars and nightclubs and hedonist spirit.
His message to the young people in Rio for the week-long World Youth Day festivities was serious: they should not make their time in Rio a one-time experience.
In his sermon, delivered from a huge white stage at the beach's northern tip, he said they should return to their home countries ready to work for social change.
"Bringing the Gospel is bringing God's power to pluck up and break down evil and violence, to destroy and overthrow the barriers of selfishness, intolerance and hatred, so as to build a new world," he said.
PRESIDENTS AT MASS
Brazilian President Dilma Rousseff, Argentine President Cristina Fernandez, Bolivian President Evo Morales and several Latin American vice presidents were among those who attended.
The Copacabana mass and a vigil the night before were to have taken place on a pasture on the outskirts of Rio, but days of unseasonable rain turned the area into a field of mud and they were moved to the beach in Rio.
"It was cold in the morning and there was a problem with a long wait for the toilets. Some people went in the sea. It was a bit chaotic. But it was lovely," said Marcel Stelsberg, 27, who came from Copenhagen with a group 65 people from Scandinavia.
"People were playing guitars and drums and singing and dancing to religious songs in different languages. Now we don't feel so alone, especially coming from Scandinavia where there are so few of us Catholics," he said.
Francis dedicated much attention in his speeches to the problems, the prospects and the power of youth. He announced that the next World Youth Day will be held in 2016 in Krakow, Poland, where John Paul II was cardinal before becoming pope.
The pope addressed Latin American bishops before leaving Brazil, telling them the Church had to shed all elitism and get closer to the people.
On Saturday night, Francis encouraged young Brazilians, who have protested against corruption in their country, to continue their efforts to change society by fighting apathy and offering "a Christian response."
Brazil, Latin America's largest nation and still the world's most Catholic country despite declining numbers of faithful, was rocked by protests last month against corruption, the misuse of public money and the high cost of living.
On Friday night he called on them to change a world where food is discarded while millions go hungry, where racism and violence still affront human dignity, and where politics is more associated with corruption than service.
The day before, during a visit to a Rio slum, he urged them not to allow their hopes of change to be extinguished. Many young people in Brazil saw this as his support for peaceful demonstrations to bring about social and political reform.
"The pope surprised us with his simplicity and clarity. He is getting through to people and they are returning to the Church," said Gabriela González, a school teacher who took four days to get to Rio by bus from Cafayate in northern Argentina.
"He told us to get out of our parishes and stir things up, get involved, and not be boring and sad."
(Additional reporting by Paulo Prada and Maria Pia Palermo)