RIO DE JANEIRO — A prison riot involving gangs vying for supremacy over the cocaine trade in the Brazilian Amazon left at least 56 people dead, the authorities in the city of Manaus said on Monday.

Riots at Brazil’s prisons are common, but the episode in Manaus, which involved decapitated bodies being thrown over the walls of the penitentiary, ranks among the bloodiest in recent decades. Officials expressed dismay over the scenes of slaughter in the Compaj prison, which held more than 1,200 inmates, about triple its official capacity.

“I never saw anything like this in my life,” Judge Luís Carlos Valois, who helped negotiate an end to the riot, said in a Facebook post. He said that dozens of people had been killed, but that it was challenging to arrive at a precise count: “There were lots of bodies. Many of them were dismembered.”