Updated

Rival prisoners fought each other with knives and sticks Wednesday at a San Salvador (search) jail, leaving at least 31 inmates dead and two dozen injured, officials said.

The riot began before dawn when a group of jailed gang members clashed with other prisoners, deputy police commissioner Pedro Gonzalez said. More than 3,000 prisoners were being held at the facility, which was designed to hold 800.

Prison director Rodolfo Garay said 30 prisoners died at the scene. One was later pronounced dead at a hospital.

Police finally regained control of the prison late Wednesday afternoon, after hours of chaos.

"Many of the injuries are serious," said emergency official Daniel Chavez. "The last (person) we took out was already dying."

Gonzalez said the riot began as a battle between rival prisoners, none of whom had escaped. Witnesses reported hearing explosions during the riot, but officials could not confirm the source of those noises.

Officials said the riot began early Wednesday after dozens of prisoners beat another inmate to death. Guards fired guns in the air but were unable to assert control, officials said.

Guards wearing ski masks to protect themselves against revenge attacks by inmates were trying to get inmates back into their cells, but some refused.

An Associated Press reporter allowed into the jail shortly after the riot began said emergency officials were trying to separate the wounded from the dead.

Central America — notably Honduras (search) and El Salvador — has struggled to make its prisons safer even as officials crack down on violent gang activity.

In May, a fire at a prison in northern Honduras killed 106 people. Officials said the fire was caused by an air conditioner short-circuit that ignited bedding and curtains and spread quickly through the prison. Survivors say the inferno was set deliberately and targeted jailed gang members.

In April 2003, an uprising in Honduras' El Porvenir prison farm (search) 220 miles north of the capital left nearly 70 people dead. A government report blamed guards for many of the deaths. Some prisoners were locked in their cells, doused with gasoline, and set on fire.