In his comments, Francis acknowledged the wretched conditions that the inmates face: overcrowding, the slow pace of justice, violence and few opportunities for education or rehabilitation. He said Bolivian institutions need to address those ills.
But he urged the inmates not to despair and to not let their suffering lead to violence.
"Suffering and deprivation can make us selfish of heart and lead to confrontation, but we also have the capacity to make things an opportunity for genuine fraternity," he said. "Don't be afraid to help one another. The devil is looking for rivalry, division, gangs. Keep working to make progress."
Francis also urged prison officials and guards to rehabilitate prisoners and not humiliate them.
Palmasola is the most notorious of Bolivia's 32 prisons, built to detain some 800 people but housing 5,000, more than four in five still awaiting trial. Inmates have the run of the place, drugs are cheaper than on the street and money buys survival.
Two years ago, 36 people died in a fierce battle between rival gangs using machetes and homemade flamethrowers. One of the victims was a 1-year-old.
Francis has frequently spoken out about the plight of prisoners, denouncing the widespread abuse of pre-trial detention and calling life sentences a "hidden death penalty." He has met with prisoners to offer them encouragement, and as pope continued to call a group of Argentine inmates he ministered to when he was archbishop of Buenos Aires.
The message is consistent with the outreach to the downtrodden and marginalized that Francis has championed as pope and in particular on his three-nation South American pilgrimage. In his most important speech of the trip, Francis on Thursday apologized for the sins and crimes of the Catholic Church against the continent's indigenous peoples during the colonial conquest of the Americas.
Francis' final event before he flew to Paraguay brought him up close to the reality of the continent's most ostracized and vulnerable to abuse.
Monsignor Jesus Juarez, who is in charge of pastoral care for Bolivia's prison system, said it was a scandal that 84 percent of inmates haven't been tried and that prisons are 300 percent beyond capacity.
Three inmates described desperate conditions and asked the pope to intercede, while two young girls played at the pope's feet, one getting up to hug him.
Analia Parada decried "constant violations of our fundamental rights and above all the deafness of administrators of justice in our country, who don't apply the law, converting Bolivian justice into judicial terrorism directed at people of scarce economic resources who can't buy justice."
Leonidas Rodriguez said he had watched "how they killed a companion and left him wrapped in a blanket. No authority did anything about it."
The third inmate, Adres de Jesus Cespedes, described his astonishment arriving at the prison to find "so many people sleeping on the ground like animals."
U.S. businessman Jacob Ostreicher spent 18 months in Palmasola after being arrested for suspected money laundering. Ostreicher, who was released in 2012 when it was revealed that he had been extorted by a ring of prosecutors, judges and government lawyers, said he doubted Francis would see the real Palmasola.
"It's the lifers who control the prison," he said. "The police officers who guard the outside of the prison push you inside the prison and you're on your friggin' own."
Inside Palmasola, everything has its price.
"Here corruption rules and he who has money can live well while the rest suffer jammed into huts with dirt floors," said Sirley Maria Vargas, the mother of a 21-year-old inmate accused of homicide. "With money you can have your own room, cleaning service, cable TV, air conditioning and Internet."
Inmates pay $1,000 for the right to a cell and $300 a month for individual cells, she said. Cellphones can be bought, and food and drugs are routinely smuggled in.
Bolivia has a notoriously corrupt judiciary, with some 1,000 judges and 300 prosecutors under investigation or on trial for corruption.
The country's prison regimen lets inmates roam outside their cells by day. Module I has streets full of men, women and children, domestic animals, stores, restaurants, a gym, a Catholic and evangelical church and workshops. Other prison sections are less hospitable, particularly Modules 3 and 4, which hold the most dangerous inmates. Module 5 houses the infirm, most with tuberculosis.
Francis has gone well beyond his predecessors in saying there is no justification for the death penalty today. He has called solitary confinement a "form of torture." In a meeting with penal lawyers last year, he denounced prison systems as "out of control" for depriving people of their dignity.
He has also offered encouragement to prisoners, twice washing the feet of detainees during Holy Thursday services in Rome and recently lunching with inmates during a visit to Naples, where he met with gay and transgender prisoners.
Palmasola reflects an all-too-frequent reality in Latin American prisons.
"What's being punished isn't the crime but rather poverty," said Juan Carlos Nunez, an investigator at Jubileo, a Catholic think tank.
The Associated Press
Error
Sorry, your comment was not saved due to a technical problem. Please try again later or using a different browser.