Prisoners who took control of a jail in Honduras on Wednesday have surrendered after guards threatened to storm the compound in the city of San Pedro Sula.
One person was killed and 11 injured in the clashes.
Police said the violence began after an inmate was accused of raping two women visiting the jail.
The man and 32 prisoners who took up arms to defend him are being transferred to jails in other parts of Honduras.
The removal of the group was a key part of the agreement to end the rebellion.
"Peace was restored in the prison with the group's transfer to other facilities," said police commander Abraham Figueroa Tercero.
Honduran prisons are notorious for overcrowding, rioting and violence; 13 inmates died in the same jail in March.
The country has the world's highest murder rate and a huge gang problem, struggles to house its inmates.
The Bishop of San Pedro Sula, Romulo Emiliani, who negotiated a peaceful solution to the stand-off, described the overcrowding crisis as "a time bomb".
He said the authorities needed to go ahead urgently with plans to build a new prison in the city.
"We cannot wait anymore, we have reached the limit. How long will we have to go on facing awful situations like that?"
Many lives were saved by the prisoners decision to surrender, said Bishop Emiliani.
"Thank God the prisoners agreed to surrender, because they were prepared to kill each other. The police also showed restraint and peace has been restored."
During the riot, prison governor Orlando Leyva said he had guards to surround the building but not to go in to "avoid a bloodbath".