MANAUS, Brazil (Reuters) - Brazil's justice minister on Tuesday proposed an overhaul of the penal system to tackle chronic prison overcrowding a day after 56 inmates were massacred in the deadliest riot in two decades.

The minister, Alexandre de Moraes, said Brazil needed to improve conditions in jails, which are home to an estimated 600,000 inmates, after visiting the prison in the jungle city of Manaus where violence erupted between rival drug gangs.

In an incident that shocked even Brazilians inured to regular outbreaks of prison violence, machete-wielding gangs decapitated inmates on Monday and threw their bodies over a wall of the penitentiary, which houses more than three times its capacity.

Hundreds of anguished relatives, hugging each other and sobbing uncontrollably, gathered outside the morgue in Manaus, waiting to discover if their loved ones were alive.

A morgue employee emerged from time to time to read from a list of those confirmed dead.

"I never imagined something like this could happen," cried Diana after learning that her son Ronei Pinheiro had been killed.

"Please help me bury my son."

Officials were forced to rent a refrigerated truck to store bodies, while medical examiners tried to identify the remains.

A war for control of the lucrative drug trade fuelled the latest gang violence in Brazil's understaffed prisons, raising concerns that Monday's massacre could unleash a wave of reprisals.

Some 223 inmates from other prisons in Amazonas state were relocated to an abandoned jail in Manaus to protect them from rival gangs following the riot.

Moraes said the solution to Brazil's chronic prison violence was not just to keep opening new prisons.

"We need to make sure those who deserve to be in jail stay there and those who committed minor crimes get out," Moraes told reporters after visiting the Anisio Jobim penitentiary. "If not, we are only providing organised crime groups with new soldiers."

The minister said 42 percent of inmates in Brazil's prisons were awaiting trial, versus a global average of just 20 percent. The prison system is among the worst in the world, according to human rights groups.

Overcrowding and violence are common, and rights groups describe medieval conditions with food scarce and cells so packed that prisoners have no space to lie down.

Brazil's federal government will provide 1.2 billion reais ($367.82 million) to states by June to beef up security and buy more X-ray machines to prevent weapons from entering prisons, Moraes said.

The prison system in Amazonas state is run by two private companies that won a 27-year public contract.

The massacre in Manaus occurred when members of a local criminal gang known as North Family, which controls the Anisio Jobim prison complex, attacked inmates from the rival First Capital Command (PCC), security officials said.

Slideshow (5 Images)

A video seen by Reuters, whose authenticity could not be verified, showed prisoners tapping the decapitated heads of four men with knifes and yelling: "These are all PCC."

SELFIE AFTER THEY ESCAPE

The riot was the deadliest since a 1992 prison massacre at the Carandiru prison in Sao Paulo state in which 111 inmates were killed.

Amnesty International called on Brazil to launch an independent investigation to bring those responsible to justice.

Police erected roadblocks and increased patrols around Manaus to hunt down more than 100 inmates who escaped from the prison during the 17-hour riot.

Sergio Fontes, security chief for Amazonas state, said he could request help from federal security forces if need be, but so far the situation was under control.

State police and army officials who were on holiday were recalled to help look for the escaped inmates, state news representatives said in a statement.

According to state officials, 54 inmates had been recaptured by Tuesday afternoon.

One inmate had posted a selfie of himself and other prisoners on his Facebook account shortly after they escaped by tearing down a wall.