The country was shocked by television images of dozens of drunken, laughing youths punching and kicking the undercover officers.

Mexico City Police Chief Marcelo Ebrard was already under fire for a crime wave that has seen widespread kidnappings and murders.

In June at least a quarter of a million Mexicans marched through the capital to protest against official failures.

“These measures are designed to contribute to the security that Mexicans legitimately demand from their government officials,” President Fox said in a television address.

President Fox invoked special executive powers to fire Mr Ebrard, a move sure to rekindle a long-running feud with Mexico City’s leftist mayor and presidential hopeful Andres Manuel Lopez Obrador.

But Mr Ebrard has blamed his firing on the rivalry between the president and Mexico City’s mayor, which has heated up this year due to a legal case that could prevent Lopez Obrador from running for president.

“The political decision made by the president is a serious error for this country,” Ebrard told local radio.

Criticism of the police has increased since the murders, especially as reinforcements took three hours to arrive in the poor slum on the edge of the city.

Despite the delay by police to respond to the murders, television crews arrived in time to film the beating.

With blood streaming down his face, one of the officers pleaded for his life and said he and his colleagues were on a drug investigation.

He survived, but the other two policemen were burned alive and their bloodied bodies were left under a street light.

The policemen had been taking pictures outside a primary school, and residents accused them of trying to kidnap children.

Many Mexicans believe that police are accomplices in a current rash of child abductions.

The next day about 1,000 police raided houses close to where the lynching took place and arrested 33 people on charges related to the killings.

Mob vengeance is frequent in Mexico due to the public’s mistrust of the police.

Private studies show only about four per cent of crimes in Mexico result in convictions.