Rio de Janeiro (AFP) - Rioting inmates beheaded rivals and burned others alive in an explosion of violence in two Brazilian jails that left at least 18 people dead on Monday, the authorities said.

Prisoners also took women visitors hostage, officials said, blaming the violence on a rift between the country's two largest gangs.

It was the latest eruption of gruesome violence to hit Brazil's underfunded and overcrowded prisons.

The clash between two rival factions in a prison in the far northern state of Roraima killed 10 on Sunday, regional government spokeswoman Jessica Laurie told AFP.

"The inmates were armed with stones and pieces of wood that they ripped from the walls. They used those bits of wood to decapitate their rivals. It was very brutal," she said.

"Seven bodies were found burned and three others beheaded."

She blamed a war between the First Capital Command (PCC) and Red Command (CV), Brazil's biggest crime gangs.

"PCC's organized crime faction gave the order to kill all members of their rival faction in the CV in every prison across the country," she said.

Another riot broke out on Monday at a prison in the northwestern state of Rondonia, officials said.

"A group of inmates blocked their rivals in their cell and set it on fire. We suspect a clash between rival factions," a police official in the state capital, Porto Velho, told AFP.

"There are thought to be eight people dead, but the bodies are burned and the medical authorities will have to confirm" the toll, a police spokesman said.

A third riot broke out Monday evening at a prison in Sao Paulo, police said.

Television footage showed several wings in flames.

"Several prisoners have escaped," a police spokesman said.

There were no immediate reports of casualties in the latest riot, which broke out in the psychiatric ward.

- Knives, clubs, hostages -

Brazilian sociologist Camila Nunes Dias said the PCC, based in Sao Paulo, and the CV, based in Rio, had split the drugs and arms trade for two decades.

Story continues

"But they broke that alliance because both groups have a strategy to expand across Brazil," she said.

Prisons nationwide have been on alert since the rival gangs declared war, Roraima state Justice Secretary Uziel Castro said.

But guards were caught by surprise on Sunday because the riot broke out during visiting hours -- a traditional time of truce, he added.

The bloodshed began when inmates of one wing broke into another at the Agricola de Monte Cristo prison in the Roraima state capital, Boa Vista.

Prisoners were armed with knives and wooden clubs, an inmate's wife who was in the prison told news site G1.

Some 100 relatives of inmates were briefly held hostage, Castro said.

The rioters demanded that a judge come to hear their demands. Instead, special operations police stormed the prison, freed the hostages and regained control by sundown.

"All the hostages were released," Castro said, adding that most of them were women.

The prison, some 3,400 kilometers (2,100 miles) northwest of Rio de Janeiro, holds 1,400 inmates -- twice its official capacity.

- Violent, overcrowded prisons -

The incident "is a reflection of the lack of interest from the state government" in the prison system, the head of the union of Roraima penal workers, Joana Moura, told the Folha de Boa Vista newspaper.

"There is no security equipment, there is not enough personnel for the tasks, and the prison officers are working beyond their capacity," he said.

Some 622,000 people were imprisoned in Brazil as of the end of 2014, according to a Justice Ministry report, which added that most of the prisoners are black males.

That makes it the world's fourth-largest prison population, the report said, after the United States, China and Russia.

Human rights groups have long complained about the deplorable conditions in Brazilian prisons.

Fourteen inmates died in prisons in the northeastern state of Ceara in late May, prompting the Inter-American Commission on Human Rights to issue a statement urging structural reforms.

In a separate incident in September, some 200 inmates rioted and escaped the overpopulated Jardinopolis prison in Sao Paulo state.