Pope Francis urged young people to shun the "ephemeral idols" of money and pleasure and cherish traditional values to help build a better world.
On the third day of his week-long visit to Brazil for World Youth Day he landed by helicopter in Aparecida, 260km west of Rio de Janeiro.
Aparecida houses a shrine of the Virgin Mary that is venerated as the patroness of Brazil, home to the biggest Roman Catholic population in the world.
It is also the site where Francis, then a cardinal in Argentina, cemented his place as a leader of the Church during a 2007 conference attended by Pope Benedict XVI.
The ongoing World Youth Day events are expected to attract more than 1 million people from around the world.
It is an effort by the Vatican to galvanize young Catholics at a time when rival denominations, secularism and distaste over sexual and financial scandals continue to lead some faithful to abandon the Church.
Security around the pope appeared much more organized than upon his Monday arrival in Rio, where adoring crowds at one point surrounded his car.
In Aparecida, where tens of thousands gathered for the pope's first public mass of the visit, Francis rode in a white popemobile with open sides and a transparent top.
Security squads kept the vehicle safely within barriers behind which tens of thousands of ecstatic faithful cheered, sang and waved flags.
The pope's desire to remain simple and close to his flock has complicated security around his visit, especially after he used a modest Fiat hatchback for his ride into Rio from the airport.
At the indoor mass in Aparecida, one of Latin America's most popular pilgrimage sites, Francis urged worshippers to embody the faith of their ancestors and trust in God.
"Let us never lose hope! Let us never allow it to die in our hearts!" the pope said in Portuguese.
In his sermon, the 76-year-old pope warned the youth of his continent to avoid the snares of modern life.
"It is true that nowadays, to some extent, everyone, including our young people, feels attracted by the many idols which take the place of God and appear to offer hope: money, success, power, pleasure," he said.
"Often a growing sense of loneliness and emptiness in the hearts of many people leads them to seek satisfaction in these ephemeral idols," he said, speaking from a modern marble pulpit.
Young people, he said in his Aparecida homily, should be "a powerful engine for the Church and for society" and be given the conditions allowing them to "work actively in building a better world."
Francis is scheduled to leave Brazil on Sunday.