A prison riot that started Sunday and left two prisoners decapitated, and two others dead, came to an end after a deal between officials and the inmates.

According to BBC News, at least 700 prisoners at the Cascavel city correctional facility were reported to be involved in the riot. The prisoners, unhappy about how the prison was run and its condition started the riot.

The riot began when inmates overpowered prison guards who were delivering coffee. Wyre Davies from BBC said rival prison gangs took advantage of the situation and began attacking each other. The rivalry was suspected of contributing to the uprising.

Two prisoners were decapitated, and two others pushed off of the roof of the building. The lawyer for the prison agents’ union, Jairo Ferreira, said the severed head of a prisoner was used to “inflict psychological torture on one of the hostage.”

An agreement was signed to end the ordeal and as a result prisoners were being transferred to another jail. After the transfer is complete, the police will have the opportunity to enter the jail and the two guards taken hostage would be released, reported the AFP.

The four inmates were not yet identified. Police will retrieve their remains once inside the jail.