Pope Francis has decried the “tragedy” of people who are forced to migrate, as he celebrated Mass in Mexico’s Ciudad Juarez city on the border with the US.
He climbed a ramp overlooking the Rio Grande that separates the city and El Paso, Texas, and laid flowers on a cross erected in memory of migrants who died trying to cross to the other side.
Earlier, he met inmates in the jail of Ciudad Juarez that was once one of the most violent cities in Mexico.
The events concluded his five-day trip.
“We cannot deny the humanitarian crisis which in recent years has meant the migration of thousands of people,” the pontiff told some 300,000 people who attended the open-air Mass.
On the US side, tens of thousands watched the event on a giant screen.
“Each step, a journey laden with injustices; the enslaved, the imprisoned and extorted; so many of these brothers and sisters of ours are the consequence of trafficking in human beings,” Pope Francis said.
Earlier on Wednesday, the pontiff visited the Cereso jail, a mixed prison which houses about 700 inmates, 250 of them women.
His visit was seen as a chance to give hope to the city’s residents, who lived through a spate of murders and rampant drug violence which meant few dared leave their homes at night.
“The problem of security is not resolved only by incarcerating; rather, it calls us to intervene by confronting the structural and cultural causes of insecurity that impact the entire social framework,” Francis told the inmates.
The pontiff’s visit came just days after 49 prisoners died in a fight between rival gang members at the Topo Chico jail in the north-eastern city of Monterrey.
Mexican prisons are notoriously overcrowded and corrupt and the meeting between inmates and the pontiff is expected to draw further attention to these problems.
The BBC’s Mexico correspondent Katy Watson says Pope Francis’s entire tour in Mexico has been focused on speaking to people who are marginalised.
He has repeatedly called on the country’s leaders to make it a better place for people to live.
On Tuesday, he told young Mexicans in the violence-hit state of Michoacan “to dare to dream”.
He urged them to reject a life of crime and to “feel your value”.