Mexico Federal police Michoacan
Mexican Federal police patrols were attacked by gunmen in Michoacan (Reuters).

A string of attacks by heavily armed gangs on Mexican police patrols have left two security agents and at least 20 criminals dead in the violence-plagued Michoacan state.

Heavily armed gunmen blocked roads and set trucks on fire to ambush police convoys in six different spots across the western state, officials said.

Federal agents repelled the attacks but 15 policemen were left injured, the interior ministry said. An unknown number of assailants were also wounded.

Authorities said the attacks were carefully planned as gangsters had hidden weapons on nearby hills.

The interior ministry didn't identify the group behind the ambushes but said it is working to apprehend those responsible.

The area is entangled in a bloody turf war between the Michoacan family drug cartel, their breakaway group the Knights Templar and the rival Nueva Generacion (New Generation) gang from the neighbouring state of Jalisco.

Fighting between the Knights Templar and federal police has been intensifying over the past week, with another four policemen killed in separate incidents.

Earlier this week gunmen also opened fire on a gathering of vigilantes in city of Los Reyes, killing five.

Some 300 self-styled law enforcers, wearing similar T-shirts, walked to the town's city hall to announce they were taking over policing in the area.

Three members of the self-defence group, a police officer and a passer-by, were killed as three gunmen fired on the crowd.

A number of self-defence squads have been formed in recent months in Michoacan by people frustrated with the continuous outbreaks of violence.

Approximately 60,000 people have been killed in drug wars between cartels in Mexico over the last six years.