A police commander was ambushed by gunmen as he left home early Monday, becoming the 12th officer slain in the central state of Mexico in five days.

The spate of killings has claimed state and municipal officers in half a dozen cities and towns since Thursday.

State authorities said the attacks appeared to be the work of criminal gangs that have sought a foothold for drug trafficking and other illegal activities in Mexico state, which borders Mexico City on three sides.

Early Monday, Nestor Peña Sanchez, a state police commander, was shot dead as he left his home in Toluca, the state capital, law enforcement officials said.

Police are frequent targets in Mexico’s rising drug violence that has claimed about 4,000 lives this year. More than 500 police officers and soldiers have been slain since President Felipe Calderon declared an offensive against drug traffickers two years ago.

Corrupt police officers often work on behalf of gangs, making it difficult to tell in many cases whether they died while enforcing the law or violating it.

In Mexico state, the burst of violence against police began Thursday with shootings of six state officers at separate road checkpoints set up to hunt for drugs and guns. Five more officers -- two state police and three municipal officers -- were shot to death Saturday.

Over the weekend, police announced the arrests of 10 suspects in the shootings. The state’s attorney general, Alberto Bazbaz, said many of the suspects were from the neighboring state of Michoacan, which serves as base for a drug trafficking gang known as La Familia.

Mexico state officials said the ambush-style attacks and use of large-bore, semiautomatic weapons signaled the likely involvement of organized-crime groups.

It was unclear whether the police slayings were related.

In other violence against police, authorities in the northern border state of Sonora reported the assassination of the state’s second-ranking police official.

Sonora officials said Juan Manuel Pavon Felix died Sunday night in an attack on the hotel where he was staying in the border city of Nogales. Assailants fired guns and tossed two fragmentation grenades as he entered the hotel; two officers were wounded.

Pavon had taken part in a police operation in Nogales,a drug smuggling hub, officials said.

In the central state of Guanajuato, four police officers were slain Monday in a pair of shootings that left two others injured, according to Mexican news reports.

In early October, hooded killers fatally shot the mayor of Ixtapan de la Sal after he reportedly rebuffed drug traffickers. Authorities said he refused to allow dealing in his town, which is best known as a spa getaway.

In September, authorities found the bodies of 24 men piled in a wooded park just outside Mexico City. Police arrested two men, including a municipal police commander, as suspects.

Ellingwood is a Times staff writer.

ken.ellingwood@latimes.com

Cecilia Sánchez of The Times’ Mexico City Bureau contributed to this report.