Gunmen posing as public officials have stormed a prison in southwestern Mexico, sparking a shootout that killed four inmates and five attackers.

Six armed men entered the prison in the Guerrero state town of Iguala after midnight on Friday by fooling a guard into thinking they were delivering an inmate, police and prosecutors said.

"Once in the prison, the armed group started a confrontation against inmates and later against guards in a security tower," the state prosecutor's office said.

The sixth assailant was injured in the attack, while a prison guard was hospitalised with a bullet wound.

State authorities and army troops restored order in the prison, the prosecutor's office said, and federal police were deployed around the facility.

One of the dead inmates was a convicted cocaine dealer, another was a kidnapper and the remaining two were imprisoned for carrying illegal weapons.

Mexican drug gangs have been known to assassinate members of rival gangs in prison, and to storm prisons to break out their own members.

Authorities were still investigating the motive behind Friday's attack.

Police had seized a stolen pickup truck used by the assailants, who were carrying heavy-calibre weapons.

Deadliest state

Guerrero is home to the fabled beach resort of Acapulco, but also high poverty and crime.

It has become the deadliest state in Mexico, with more than 2,300 murders in 2012 amid deadly turf battles between drug gangs.

The National Human Rights Commission said in November that violence has increased inside Mexico's prisons, with a growing number of riots, fights, escapes and homicides.

Also on Friday, officials in the central state of Morelos said four inmates escaped from their cells in the town of Xochitepec, using a rope and a ladder to climb one of the prison's towers and jump a wall with the help of a guard.