At least 60 inmates have been killed, many of them decapitated, in a prison riot in the Amazon jungle city of Manaus, officials said on Monday, in one of the worst incidents of jail violence in years in Brazil.

The 17-hour riot broke out on Sunday afternoon and lasted through the night at a prison on the outskirts of Manaus, the capital of Amazonas state, Sergio Fontes, the public security secretary of the state, said.

"This is the biggest prison massacre in our state's history," Fontes said. 

"Many (victims) were decapitated, and they all suffered a lot of violence," he told a press conference.

Two of the biggest crime gangs of Brazil began fighting last year over control of several prisons, and authorities in Amazonas believe that's the reason behind the first riot of 2017.

READ MORE: Deaths as riot breaks out in Brazil prison

Authorities have counted 60 bodies so far, all of them inmates, the head of the state's prisons administration, Pedro Florencio, told journalists.

Officials said they were working to determine whether any prisoners had escaped.

The riot ended after the inmates freed the last of the 12 prison staffers they had held hostage.

Judge Luis Carlos Valois, who negotiated the end of the riot with inmates, said he saw many bodies that were quartered.

"I never saw anything like that in my life. All those bodies, the blood," Valois wrote on Facebook.

Fontes said the inmates made few demands to end the riot, which hints at a killing spree organised by members of a local gang against those of another that is based in Sao Paulo.

The secretary said officers found a hole in a prison wall through which authorities believe weapons entered the building.

OPINION: The barbarism of Brazilian prisons

Valois said during the negotiations, inmates only asked "that we did not transfer them, made sure they were not attacked and kept their visitation".

In another prison in Amazonas, 87 inmates escaped in the first hours of Monday, Fonte said. One of the inmates posted a picture on Facebook as he left the prison.

The violence at Anisio Jobim began after a group of inmates exchanged gunfire with police and held 12 prison guards hostage in the largest prison in Manaus, an industrial city on the banks of the Amazon River, local TV network Globo TV reported.

Fontes said 74 prisoners were taken hostage during the riot, with some executed and some released.

Overcrowded prisons

Brazil has the fourth largest prison population behind the US, China and Russia. 

The massacre was the latest clash between inmates aligned with the Sao Paulo-based First Capital Command drug gang, Brazil's most powerful, and a local Manaus criminal group known as the North Family, Reuters news agency reported.

Sunday's riot was the deadliest in years. A 1992 rebellion at the Carandiru prison in Sao Paulo state saw 111 inmates killed, nearly all of them by police as they retook the jail.

Horrific conditions and inter-gang violence are seen in many facilities, some of which are essentially run by drug gang leaders who continue to run their criminal enterprises on the outside despite being locked up.

Riot police patrol outside a prison after clashes between rival gang factions in Boa Vista [Reuters]

Source: News agencies