Clashes, which took place between prisoners wielding knives and homemade weapons, lasted several hours [Reuters]

A fight between rival gangs inside a prison in northern Mexico has left 31 inmates dead in the latest violence to erupt inside the country's overcrowded jails, local officials say.

Clashes between prisoners wielding knives and homemade weapons started around mid-day and were controlled several hours later in Altamira, Tamaulipas, on Mexico's Gulf coast, Guillermo Martinez, a state government spokesman, said on Wednesday.

Another 13 prisoners were wounded in the brawl, Tamaulipas state's Public Safety Department said in a statement.

The fight started when a group of inmates burst into a section of the prison they were banned from and attacked the prisoners housed there, the department said.

Local media said the fight was between members of the rival Gulf and Zetas drug cartels but authorities wouldn't confirm the reports.

Powerful drug cartels are fighting for control of smuggling routes along the US-Mexico border and rivalries often spread into the prison system, where prisoners held on federal drug charges are mixed with common criminals.

Last October, 20 people died in a prison fight at another jail in Tamaulipas and in July, 17 inmates were killed in Ciudad Juarez, Mexico's most violent city, across from El Paso, Texas.

More than 46,000 people have died in Mexico in the past five years since President Felipe Calderon launched an assault on drug gangs. Packed and inefficient prisons often suffer from corruption and mass escapes.

Violence exploded in Tamaulipas state after the Zetas gang broke away from the Gulf cartel and began battling their former employers for turf.

Source: Agencies