Speaking from a white stage and looking out over the enormous crowd, Francis urged young Catholics to go out and spread their faith "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 said to applause in his final homily of World Youth Day.
The pope's trip, which ends when he takes off for Rome Sunday night, was hailed as a great success by clergy, pilgrims and everyday Brazilians alike. The pope's nonstop agenda was followed live on television for all seven days. His good nature and modesty clearly charmed the nation that has more Catholics than any other.
"This trip was a success. It was great to see the pope on his continent, in his house, speaking his language every day," said the Rev. Federico Lombardi, the Vatican spokesman. "It's been a great experience to see this pope being even more spontaneous in his own house ... so comfortable in what he was doing."
Nearly the entire 4 kilometer (2.5 mile) crescent of Copacabana's broad beach overflowed with flag-waving faithful, some of them taking an early morning dip in the Atlantic and others tossing T-shirts, flags and soccer jerseys into the pontiff's open-sided car as he drove by. Francis worked the crowd, kissing babies, taking a sip of mate tea handed up to him and catching gifts on the fly.
Even the normally stern-faced Vatican bodyguards let smiles slip as they jogged alongside Francis' car, caught up in the enthusiasm of the crowd.
The numbers clearly overwhelmed the area's services: The stench of garbage and human waste hung in Rio's humid air, and the beach and adjoining chic Atlantic Avenue looked like an improvised refugee camp plunked down in the middle of one of the most beautiful cities in the world. Copacabana's famous mosaic sidewalks were strewn with trampled cardboard, plastic bags, empty water bottles and cookie wrappers as trash collectors in orange uniforms tried to restore order.
"You'd think they could at least put their garbage in all the bins," said Jose da Silva, a 75-year-old retired farm worker who supplements his meager income by collecting empty cans for recycling. "I'm also pretty surprised that people who call themselves Christians would throw away all this food."
Many of the youngsters on hand for the Mass spent the night on the beach, an all-night slumber party to end the Catholic youth fest, with pilgrims wrapped in flags and sleeping bags to ward off the cold. They danced, prayed and sang and waited in long lines in front of the armadas of portable bathrooms along the beachfront.
"We were dying of cold but it was worth it," said Lucrecia Grillera, an 18-year-old from Cordoba, Argentina, where Francis lived for a time before becoming pope. "It was a tiring day, but it was a great experience."
By morning, vendors hawking World Youth Day trinkets, T-shirts, hats and flags were doing brisk business as pilgrims snapped up souvenirs before heading home. Jehovah's Witnesses stood by stands stocked with pamphlets offering to explain "What does the Bible really teach" but they had few takers.
The Vatican said more than 3 million people were on hand for the Mass, based on information from World Youth Day organizers and local authorities who estimated two-thirds were from outside Rio. That was far higher than the 1 million at the last World Youth Day in Madrid in 2011 or the 850,000 at Toronto's 2002 concluding Mass.
Only Pope John Paul II's Mass during his 1995 visit to Manila, the capital of the Philippines, topped Rio's numbers, with an estimated 5 million people taking part. Third place among papal Masses now goes to Rome World Youth Day in the 2000 Jubilee year, when 2 million people participated. A similar number attended John Paul's final Mass in Krakow, his Polish hometown, in 1979, during his first visit to his homeland as pope.
As if recalling that historic Mass, Francis announced on Sunday that the next World Youth Day would be held in Krakow in 2016.
Not all of Sunday's attendees were paying attention to the Mass: Kids posed for random photos with people holding flags, snoozed and packed up their makeshift camps. Finding food was a core concern, with long lines of bedraggled pilgrims snaking out of cafes and ice cream vendors being mobbed by youths starved for breakfast.
The presidents of Brazil, Francis' native Argentina, Bolivia and Suriname were on hand for the Mass, as were the vice presidents of Uruguay and Panama. Receiving a special honor was a couple Francis met on Saturday after Mass at Rio's cathedral; they had brought him their anencephalic baby daughter to be blessed. Francis invited them to participate in the offertory procession on Sunday, at which the father wore a T-shirt that read "Stop abortion."
After Sunday's Mass, Francis was meeting with the bishops of Latin America and the Caribbean, as well as holding a thank-you audience with some of the 60,000 volunteers who organized the youth festival. He was leaving for Rome Sunday night.
"It was such an excellent week, everybody was in such good spirit, you could just feel a sense of peace," said Denise da Silva, a Rio de Janeiro Catholic who was sitting alone on the beach Sunday morning, a Brazilian flag painted on her face. "I have never seen something here in Rio so marvelous as what we have just lived."
Francis has spent the week emphasizing a core message: of the need for Catholics, lay and religious, to shake up the status quo, get out of their stuffy sacristies and reach the faithful on the margins of society or risk losing them to rival churches.
According to census data, the number of Catholics in Brazil dipped from 125 million in 2000 to 123 million in 2010, with the church's share of the total population dropping from 74 percent to 65 percent. During the same time period, the number of evangelical Protestants and Pentecostals jumped from 26 million to 42 million, increasing from 15 percent to 22 percent of the population in 2010.
Francis repeated that stirring message Sunday in his homily, saying he was counting on young Catholics in particular to be "missionary disciples" in spreading the faith.
"Bringing the Gospel is bringing God's power to pluck up and break down evil and violence, to destroy and overthrow the barriers and selfishness, intolerance and hatred, so as to build a new world," he said.
It seemed the message was getting through.
"I used to go to Mass every week but now I go every other week, if that," said Larissa Miranda, a 20-year-old law student from rural Rio de Janeiro state who moved to the city two years ago. "But this event had made me realize that I need to get active again and get back to church every week."
The Rev. Jean-Luc Zadroga, a Benedictine monk who was leading a group of 14 students from a Catholic university in Latrobe, Pennsylvania, said it was clear Francis had connected with the crowd, particularly the locals.
"He's really trying to reach out to Catholics who have fallen away from the church or disappointed with the church and I think it's working," he said.
Associated Press writer Marco Sibaja and Bradley Brooks contributed to this report.