The mayor of Mexico City has welcomed a sacking by President Vicente Fox that could resolve a political crisis.
The mayor said the power of the people had brought about the move
Mexico's attorney general was fired after trying to bring popular Mayor Andres Manuel Lopez Obrador to trial.
Mr Lopez Obrador, a front-runner in the 2006 presidential race, said the firing of attorney general Rafael Macedo would improve the atmosphere in Mexico.
Huge crowds have rallied behind the mayor, who would have been barred from the presidential race if found guilty.
Correspondents says the move is an extraordinary climb-down by Mr Fox.
The BBC's Claire Marshall in Mexico City says he seems to be clearing the way for the mayor to stand for the presidency.
Opinion polls have shown that Mr Lopez Obrador enjoys a clear lead for next year's election.
He says he believes that efforts to prosecute him over the land dispute are an attempt to stop him from running.
In a press conference on Thursday, the mayor repeated his claims that the process against him had always been political rather than legal.
The power of the people had brought about this change, he told reporters.
Mr Fox's move "will encourage dialogue, improve the legality of decision making, and strengthen our democratic institutions," he said.
President Fox said he had acted on Wednesday "to promote national unity", and called for "a calm exchange of ideas".
The former attorney general acknowledged that his resignation was due to larger political factors.
"The country's current situation required I resign for love of my country," Mr Macedo de la Concha said, quoted by the Associated Press.
Although not officially confirmed, presidential counsel Daniel Cabeza de Vaca is tipped to take over as attorney general.
Mexico's Congress removed Mr Lopez Obrador's immunity earlier this month and opened the way for his prosecution on contempt of court charges.
On Monday, he returned to work for the first time since being stripped of immunity.
Since he took office in December 2000, Mr Lopez Obrador - who belongs to the left-wing Party of the Democratic Revolution (PRD) - has become one of the country's most popular politicians.
Sunday's protest was one of the biggest marches Mexico had ever seen. Organisers said 1.2 million people were present, though officials put the number at 120,000.
Mr Lopez Obrador is accused of breaching a court order after allowing the construction of an access road to a city hospital said to go through a disputed plot of expropriated land.