SAN SALVADOR, El Salvador (AP) – Rival gang members battled each other with homemade weapons and shovels in a riot that erupted in a maximum-security prison in western El Salvador and left 17 inmates dead, officials said Saturday.

The riot was sparked late Friday at the prison in Apanteos, 40 miles west of San Salvador, when a jailed gang member got into an argument with a guard as inmates were going into their cells to go to sleep, authorities said.

The prisoner grabbed the guard and rival gang members around them began fighting each other and tearing down six of the prison’s flimsy interior walls to get at other cell blocks.

The guards then fled as hundreds of prisoners battled, mostly with homemade weapons, shovels and pieces of broken wall.

Government human rights prosecutor Beatrice de Carrillo described the riot as “the worst massacre in recent years.”

Deputy police director Luis Tobar Prieto said Saturday officials had regained control and all those killed were prisoners. Several people were injured in the melee, although none seriously, he said.

The prison, with a listed capacity of 1,800 people, houses more than 2,000 prisoners, many considered to be the most dangerous in the country.

About 100 police were sent in to keep the peace, while buses carried dozens of prisoners to the maximum security Santa Ana facility, an effort to ease overcrowding and separate feuding groups.

Central American jails have long struggled with overcrowding and deadly riots that are often sparked by fights between rival gangs.

Overcrowding is fueled in part by a regional gang crackdown that has filled prisons with rival groups.

In Guatemala, a gang was blamed for initiating riots that left 35 inmates dead in 2005. In El Salvador, 31 inmates were killed in 2004 during a battle between gang and non-gang prisoners. And a rash of violence in Honduran prisons killed more than 180 prisoners in 2004-2005.