RIO DE JANEIRO – An attack by members of one crime gang on rival inmates touched off a riot at a prison in the northern state of Amazonas, leaving at least 56 dead, including several who were beheaded or dismembered in the worst bloodshed at a Brazilian prison since 1992.

Authorities said the riot that raged from Sunday afternoon into Monday morning grew out of a fight between two of the country's biggest crime gangs over control of prisons and drug routes in northern Brazil.

In a separate incident Monday evening, four inmates were killed at another Amazonas prison. Police were investigating whether there was a connection between the mass killings at the Anisio Jobim Penitentiary Complex and the later ones at Unidade Prisional do Puraquequara.

Amazonas authorities initially reported 60 dead in the Anisio Jobim prison in Manaus, but the state public security secretary's office later reduced that figure to 56. Officials also said 112 inmates escaped during the riot.

There were 1,224 inmates in the prison, which was built to hold 592, Amazonas state public security's office said. The prison is run by a private company that is paid according to the number of inmates.

Twelve prison guards were held hostage by the inmates during the riot, though none was injured.

"This is the biggest prison massacre in our state's history," Public Security Secretary Sergio Fontes said at a news conference. "What happened here is another chapter of the war that narcos are waging on this country and it shows that this problem cannot be tackled only by state governments."

Fontes confirmed that many of the dead had been beheaded. Judge Luis Carlos Valois, who negotiated the end of the riot with inmates, said he saw many bodies that had been quartered.

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

It was the largest death toll during a Brazilian prison riot since the killing of 111 inmates by police officers in the Carandiru penitentiary in Sao Paulo in 1992. Police said they acted in self-defense then.

Two other prisons in Manaus also reported riots since Sunday. At one, 72 prisoners escaped, including an inmate who posted a picture of himself on Facebook as he left. Amazonas police were also looking for any links between those two incidents and the riot at Anisio Jobim.

Authorities said that of the 184 inmates who escaped Amazonas prisons the last two days, only 40 had been recaptured.

Fontes said the inmates at Anisio Jobim made few demands to end the riot, saying that hinted at a killing spree organized by members of a local gang, the Family of the North, against those of the First Command of the Capital that is based in Sao Paulo.

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

Authorities said officers found a hole in a prison wall through which weapons entered the building. A policeman was wounded in exchange of gunfire with the inmates. Several firearms were found when police searched the prison after the riot.

Jose Vicente da Silva, a former national public security secretary, said the incidents in Manaus were a result of Brazil's severe recession and poor management of the prison system.

"Since 2014 homicides in prisons of Amazonas are double the national average, and last year they cut their public security budget by 50 percent due to austerity measures. This incident is a repetition in a bigger scale," Da Silva told The Associated Press. "Every year 500 inmates die in Brazilian prisons. With the current economic crisis and the budget cuts, the gangs get even bolder."

The First Command, nationally known as PCC, is the most powerful drug and prison gang in Brazil and it has been trying to extend its reach to northern prisons dominated by the Family of the North. To counter, Family of the North associated with the Red Commando of Rio de Janeiro, the second biggest crime gang in Brazil.

To avoid another wave of killings of PCC members, Amazonas authorities said they had relocated 130 inmates to a prison that was opened in 1907 but deactivated in October because of substandard conditions.