Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

RIO DE JANEIRO — An attack by members of a crime gang on rival inmates touched off a riot at a prison in the northern Brazilian state of Amazonas, leaving at least 56 dead, authorities said.

Several of the victims were beheaded or dismembered in the worst bloodshed at a Brazilian prison since 1992.

Authorities said the riot, which 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.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Relatives of prisoners await news after a bloody prison riot Monday in the Amazon jungle city of Manaus, Brazil. Michael Dantas / Reuters

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 Anisio Jobim Penitentiary Complex and the later ones at Unidade Prisional do Puraquequara.

Amazonas authorities initially reported that 60 people were killed at Anisio Jobim in Manaus, but the state public security secretary's office later lowered the 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, the 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 during the riot; none were 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. He said the inmates made few demands to end the riot, which he said indicated a killing spree organized by members of a local gang, the Family of the North, against those of the First Command of the Capital, based in Sao Paulo.

Judge Luis Carlos Valois, who negotiated the end of the riot, 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.