RIO DE JANEIRO — At least 52 people were killed in a prison riot Monday in northeastern Brazil, authorities said, the second time since May that a clash between rival gangs exploded into a horrifying bout of violence.
At least 16 of the victims were decapitated, authorities said. Others were asphyxiated.
It took five hours for prison officials to quell the riot at the Altamira jail in Para state. The clash erupted early Monday after members of one gang infiltrated another part of the jail. Video and pictures aired by local media showed flames shooting out of the prison.
Inmates took two prison officials as hostages. They were reportedly freed unharmed. Authorities did not immediately say which gangs were involved.
‘‘The state government will identify the leaders of the two factions involved in the confrontation so that we can put them in federal prisons,’’ Para Governor Helder Barbalho said Monday afternoon.
The clash echoed a riot in northwestern Brazil on May 27, when a power struggle involving the Northern Family, Brazil’s third-most-powerful gang, led inmates to strangle or stab at least 55 people, some in front of visiting families.
The violence illustrated the mounting insecurity in Brazil’s notoriously underfunded and overcrowded prisons — and the challenge facing officials as they struggle to restore order to the system. Brazil’s inmate population has swelled from about 500,000 inmates a decade ago to an estimated 800,000.
President Jair Bolsonaro, elected last year on promises to crack down on violent crime, has described plans to ‘‘stuff prison cells with criminals.’’
‘‘I’d rather a prison cell full of criminals than a cemetery full of innocent people,’’ he said. ‘‘We will build more if necessary.’’
The Altamira was already over capacity, according to local media. It was built for 200 detainees, but currently houses 311.
Unconfirmed images and video on social media appeared to show chaos at the prison, with black smoke billowing out from inside the prison walls. People can be seen running around inside. One video appeared to show decapitated heads piled up against a wall beside a man waving a machete.
Politicians seized on the bloodshed as more reason to crack down on criminals.
‘‘In these fights between criminal factions, I root for the machete,’’ said Gilson Cardoso Fahur, a congressman from Parana state, one of many politicians who recently won office on the promise to get tough on crime in a perennially violent country.
The deteriorating conditions at the country’s prisons are one result of Brazil yearslong war on crime. Some prisons are so overcrowded that inmates sleep standing up, with hands tied to bars to keep them upright.
Analysts worry that the current conundrum in the system — too many people; too little funding — is a deadly one.
‘‘There are almost twice as many prisoners as there is prison space,’’ said Bruno Paes Manso, a researcher the University of Sao Paulo’s Violence Studies Center. ‘‘The result is that this insecurity strengthens gang command and prison leadership, which has grown in Brazil in the last 10 years.’’
He predicted that extraordinary prison violence will not only continue in the coming years — it will worsen.
‘‘By insisting on high incarceration in overcrowded prisons, Bolsonaro wants to increase the dose of the poison that is killing us,’’ he said.
For the last four years, Brazil’s largest gangs have been waging a turf war that has spread across the country. Increasingly profitable drug routes have caused the country’s largest gangs to expand their presence, form alliances with smaller gangs, and challenge rivals. Clashes led to record high homicide rates throughout the country in 2017.
Many of these gangs see prisons, which are effectively run by gang lords, as their command centers. They use smuggled cellphones and videos to give orders and set rules. Inmates are forced to pledge allegiance to survive. Deadly prison riots are increasingly common, as leaders seek to cement their power through extreme violence.
Many prisons are controlled at the state level, so the Bolsonaro administration has called on states to build more prisons and for drug lords to be moved to federal penitentiaries. Building more prisons has so far seemed unlikely, however, given funding challenges.
The Brazil office of Human Rights Watch has investigated the country’s prisons. Maria Laura Canineu, the organization’s Brazil director, called the violence the most visible sign of a structurally defective system.
‘‘Nationwide, 40 percent of people in detention are awaiting trial,’’ she said. ‘‘Most inmates are black young men with low levels of education who depend on understaffed public defenders’ offices for their legal defense.’’
She said she expects prison gangs to strengthen as the facilities are stuffed with more inmates, many of whom were already gang members — or soon will be.
‘‘It is really sad to see this [violence] again,’’ she said. ‘‘But not surprising, unfortunately.’’