More than a dozen cops were shot dead in Mexico during an ambush by suspected drug cartel hitmen — marking one of the bloodiest attacks on the country’s law enforcement since President Andrés Manuel López Obrador took office last year.

The attack unfolded in the municipality of Aguililla in the state of Michoacan on Monday, according to the federal public security ministry.

The ministry said four officers were killed, but state police in Michoacan reported that 13 were confirmed dead and three injured.

Photos circulating on social media showed some police cars on fire and others riddled with bullet holes. The bodies of slain officers can be seen sprawled on the ground.

A state official who requested anonymity confirmed the photos to Reuters and said the shooting was the result of an attack by local gangsters.

Three police cars were targeted in the shooting spree, the official said, adding there was no indication that any suspected gang members were killed.

Turf wars between drug gangs — mainly the Jalisco New Generation Cartel (CJNG) and its enemies — have long thrown Michoacan into a state of upheaval.

The group has used intimidation and bribery to control local law enforcement, officials said. Police salaries are minuscule compared to the group’s financial backing — fueled by incoming funds from trafficking crystal meth.

The heavily armed CJNG has kept a stronghold in the state, and the cartel was blamed for a series of attacks on police in the neighboring state of Jalisco back in 2015.

Fifteen officers were killed in a single ambush in the western state that year — during six weeks of violence in which a total of more than two dozen officers were slaughtered. The bloodbath concluded with the downing of an army helicopter on May 1.

More than 29,000 murders were recorded in Mexico last year — a record for the country. López Obrador had pledged to restore peace and order — but the violence has continued and this year could conclude with an even higher murder tally.

With Post wires