Pope Francis on Sunday encouraged hundreds of thousands of young people gathered in southern Poland to "believe in a new humanity," which is stronger than evil and refuses to use borders as barriers.

His appeal came at the end of World Youth Day, a weeklong event which draws young Catholics to a different city every three years in a polyglot spiritual pep rally.

The event was Francis' main focus during his pilgrimage to Poland, which also included meditation at the Auschwitz death camp and an imploration to God to keep away a devastating wave of terrorism.

For a second straight day, a huge crowd filled a green field in the gentle countryside outside of Krakow for Francis, whose five-day trip introduced the Argentine to Eastern Europe.

Some of the faithful had camped out overnight after an evening of entertainment and prayer with the pope there that drew 1.6 million people, according World Youth Day organizers.

Sunday's faithful numbered at least in the hundreds of thousands, similar to the number of attendants seen at the pope's other public appearances in the overwhelmingly Catholic country in the past days.

The pope used his several encounters with the young pilgrims -- from mega-gatherings to a private lunch with only a dozen of them from five continents -- to encourage a new generation to work for peace, reconciliation and justice.

God, said Francis in his final homily of the pilgrimage, "demands of us real courage, the courage to be more powerful than evil, by loving everyone, even our enemies."

"People may judge you to be dreamers, because you believe in a new humanity, one that rejects hatred between peoples, one that refuses to see borders as barriers and can cherish its own traditions without being self-centered or small-minded," Francis told his flock before him, many of them in their late teens, 20s or 30s.

Earlier in his pilgrimage, Francis had expressed dismay that many people and places aren't welcoming to refugees or those fleeing poverty in their homelands.

As hundreds of thousands of migrants arrive in smugglers' boats on Europe's southern chores, some nations on the continent, notably in central and eastern Europe, have thrown up fences to keep the refugees out. Poland has been among the countries which have refused to take in many refugees, saying it already hosts many Ukrainian migrants.

Attending Francis' closing Mass on Sunday were some of Poland's top leaders, including President Andrzej Duda and Jaroslaw Kaczynski, head of the conservative ruling Law and Justice party. Kaczynski is widely regarded as the most powerful figure in Poland's politics and toes a generally pro-Catholic but anti-migrant line.

On his way to the site, Francis made a stop to bless two buildings run by the Catholic charity Caritas, one built as a day center for the elderly and the other to be a storehouse for food for the needy called "The Bread of Mercy."

As he left, Francis nibbled on some dark bread from a big, round loaf offered by women in traditional Polish costumes. He nodded in approval as he chewed away.

The World Youth Day events, held every three years in a different country, took place amid very high security following a string of extremist attacks in Western Europe. No incidents were reported, according to police.

Later, Francis announced that the next World Youth Day will take place in Panama in 2019.