Brazilian police raided a prison in Rio de Janeiro to investigate allegations of corruption among the guards - and were let in by the inmates.
Police said some prisoners at the Polinter de Queimados jail had keys to the cells and controlled who went in and out.
Other inmates were being forced to pay for privileges such as visiting rights for relatives.
The only guard who was at the facility when police arrived has been arrested.
A pistol, ammunition and several unauthorised mobile phones were seized, police said.
They also confiscated accounts books which allegedly detailed payments made by prisoners for larger cells and better conditions.
The prison, in the Rio suburb of Baixada Fluminense, holds 150 inmates who are awaiting trial.
The raid was carried out by a police task force that targets organised crime, after allegations that guards were receiving money from prisoners.
Brazilian prisons have long had a reputation for violence, corruption and poor conditions.