Pope Francis is closing the biggest-ever Roman Catholic youth festival event with a Mass on Brazil's Copacabana beach.
Many of the pilgrims had slept on the beach after attending an all-night vigil, which the Pope also led.
Sunday's ceremony marks the end of his first foreign trip since becoming pontiff in March.
Pope Francis, who has spent five days in Brazil, is set to fly back to Rome later on Sunday.
The BBC's Wyre Davies in Rio says almost every inch of the two-and-a-half mile long beach was occupied ahead of the Mass, as most of the young people stayed after the vigil, pitching tents or sleeping in the open.
Female activists held a demonstration nearby in support of abortion and women's rights.
But our correspondent says the Pope and the Church hierarchy will be delighted at the huge turnout and the way Francis has been received by pilgrims from across the globe.