The attempt was described as a military style battle in which both prisoners and associates on the outside were armed.
Brasilia: At least 21 people died on Tuesday in an attempted breakout from a prison in northern Brazil aided by an armed group on the outside trying to blow up a wall, officials said.
The Para state security service described the mass escape attempt at the Santa Izabel Penitentiary Complex, near the Amazon rainforest city of Belem in Para state, as a military style battle in which both prisoners inside and associates on the outside were armed.
"In the rescue attempt, explosives were used against one of the walls," the agency said in a statement. "The attempt was supported by an extremely heavily armed group. According to preliminary reports, the prisoners also had weapons inside the prison," the statement said.
Prison guards fought back in "an intense exchange of gunfire," it said. The confirmed dead so far included 20 prisoners and outside attackers, plus one guard. Another five guards were injured, including one seriously.
A headcount was underway to establish whether anyone escaped, while a police SWAT team was reinforcing security. Police had recovered two rifles and five handguns at the scene, the statement said.
Brazil is one of the world's deadliest countries, with around 60,000 homicides a year, and the prisons are notoriously overcrowded and violent.
There were 726,712 inmates as of June 2016 and capacity for only 368,000, according to the most recent official statistics.
Powerful drug gangs routinely take their turf wars from the streets of Rio de Janeiro and other big cities into penitentiary facilities.
In the worst cases, security staff are reduced to bystanders as criminal bosses run daily life. In one of the bloodiest episodes, 56 people were killed in an uprising in a prison in the city of Manaus in Brazil's Amazon in 2017.
In January, fighting between gangs at a prison in northeastern Ceara state left 10 dead. That bloodshed took place in the Itapaje Public Prison, about 78 miles (125 kilometers) from the state capital Fortaleza. A few days earlier, at least 14 people had been gunned down at a nightclub in Fortaleza.
Local media reported that the massacre, conducted by armed men who arrived in three cars, was related to disputes between rival drug traffickers. Adding to Brazil's security woes, the police force is regularly accused of breaking the law in carrying out extrajudicial killings, falsifying evidence and failing to investigate its own officers.
Human Rights Watch reported earlier this month that police had killed 4,224 people in 2016 -- the last available figures -- about 26 percent more than in 2015. The streets are also deadly for police: 437 were killed in 2016, the report said.