A fight among inmates armed with makeshift knives, clubs and stones left 31 of them dead in a Mexican prison that holds many members of drug cartels, authorities said.

Another 13 prisoners were wounded in the brawl in the Gulf Coast city of Altamira, 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 from which they were banned and attacked the prisoners housed there.

Local media said the fight was between members of the rival Gulf and Zetas drug cartels but authorities would not confirm the reports. Tamaulipas state has been the scene of bloody turf battles between the two former allies.

Tamaulipas officials said many of the dead were killed with makeshift knives. A state official who spoke on condition of anonymity because of the investigation said several were beaten to death with clubs or stones.

Soldier and marines managed to take control of the prison, the official said.

The public safety department said 22 of the inmates killed had been serving sentences for state crimes and nine for federal offences. It gave no other details.

The port of Altamira in southern Tamaulipas, near the border with the state of Veracruz, is in a region that has seen a spike in drug violence in the last two months. Authorities say the port is used to bring cocaine and precursor chemicals used to make methamphetamine into Mexico.

In 2010 four inmates at the Altamira prison were killed when an armed gang stormed in during a prisoner transfer. Authorities did not confirm reports that the raid was an attempt to free prisoners. Gang raids on prisons are common in Tamaulipas.