KRAKOW, Poland — Pope Francis encouraged hundreds of thousands of young people at a global gathering Sunday to “believe in a new humanity” that is stronger than evil and refuses to see borders as barriers.

His appeal came at the end of World Youth Day, a weeklong event held in southern Poland this year that draws young Catholics from around the world every two to three years to a different country for a spiritual pep rally.

The youth gathering was Francis’ main focus during his pilgrimage to Poland, but over five days in this deeply Catholic nation he also prayed in silence at the former Nazi Auschwitz death camp and implored God to keep away a devastating wave of terrorism now hitting the world. He also met with Poland’s political and church leaders.

For the second straight day, a huge crowd filled a field Sunday in the countryside outside Krakow to see Francis, who was visiting central and eastern Europe for the first time.

Security was very tight throughout the pope’s five-day visit, but he encountered huge crowds day after day without incident and arrived back in Rome on Sunday evening.

Sunday’s faithful numbered at least in the hundreds of thousands. The Rev. Federico Lombardi, a Vatican spokesman, referred to an estimate by Polish authorities of 1.5 million at Sunday’s closing Mass.

On his way to the airport Sunday, Francis met with hundreds of young volunteers to thank them for their work. Looking at the prepared speech in his hand, he said with annoyance, “Five pages?” and then began speaking freely in his native Spanish.

“Do you want to be hope of the future?” he asked, getting an enthusiastic “Yes!”