At the World Youth Day gathering, the pontiff urged young people to embrace hope and put prayer at the centre of their lives.
The event took on a carnival atmosphere with pilgrims dancing, singing and waving flags.
The visit marks the 1,050th anniversary of Poland's adoption of Christianity.
Some reports said as many as three million pilgrims, mostly young people, were at the mass, held in a vast field called the Campus Misericordiae near the southern city of Krakow.
Police declined to give an estimate of numbers.