By Jon Leyne
BBC News, Teheran
Mr Ahmadinejad has even been criticised by fellow conservatives
If President Ahmadinejad fails to win re-election on 12 June, he would be the first Iranian president to be unseated at the polls since the foundation of the Islamic Republic.
On the face of it, it appears a distinct possibility.
Mr Ahmadinejad is blamed by many Iranians for the parlous state of the economy. They ask what happened to the windfall of oil revenues, from the time when oil reached nearly $150 a barrel.
Ordinary Iranians battle ever rising prices, and growing unemployment.
There has been criticism, even from fellow conservatives, about the confrontational tone of the president's foreign policy.
One of the presidential challengers, Mohsen Rezai, has warned that Iran is headed for an "abyss". Strong language indeed from a former head of the Revolutionary Guards.
In fact, Mr Ahmadinejad has failed to win the endorsement of the main conservative, or "Principalist", factions.
Even the support of the Supreme Leader, Ayatollah Khamenei, seems to be wavering.
The leader issued a rare public rebuke this week to the president in a dispute over the merger of two ministries.
The issue may seem arcane, but it is almost unheard of for the president, especially this president, to be publicly countermanded by the leader.
And yet, no-one should underestimate Mr Ahmadinejad's ability to secure and maintain power.
He still has the support of the government machine, the military, the Revolutionary Guards, and the state owned media. Whatever their immediate differences, Ayatollah Khamenei seems to have a soft spot for his controversial president.
A glimpse of how Mr Ahmadinejad uses the levers of power emerged during the last week, when he was accused by rivals of using the government's resources to bus huge numbers of supporters into his rallies across the country.
It is claimed that whenever the president visits provincial cities, schools and government offices are closed for the day, so that students and soldiers can swell the numbers at his rallies.
By contrast one candidate was recently refused permission to speak in a provincial city, because it was said he would cause traffic problems.
Mr Ahmadinejad will certainly be hoping to benefit from the votes of members of the revolutionary guards, the Basij militia, possibly also civil servants and teachers.
Mahmoud Ahmadinejad: holds levers of state, great campaigner
Mir-Hossein Mousavi: former pm, not a great campaigner
Mehdi Karroubi: only candidate to call himself "reformist"
Mohsen Rezai: former head of Revolutionary Guards
And he has been working hard for support in the countryside, with many villagers benefitting from home loans, water supplies, electricity, even telephones, for the first time.
The challenge for his rivals is to persuade enough of the malcontents to go out and vote.
When Mohammed Khatami upset the establishment to become president in 1997, he overturned predictions with a turnout of nearly 80%.
But the more liberal-minded Reformist faction that he represented was deeply demoralised by his failure to achieve more during eight years in office.
Many of his former supporters simply will not turn out to vote this time. In the last parliamentary elections, reformists failed to win a single one of the 30 seats in Tehran. And that was not just because many of their candidates were disqualified.
Former President Khatami is now putting his weight behind the campaign of Mir-Hossein Mousavi.
Mir-Hossein Mousavi was the last Iranian prime minister
Mr Mousavi has become the leading challenger. He was prime minister from 1980-88, when he gained a reputation for competent economic management.
So his strength works on Mr Ahmadinejad's perceived weakness. Until recently he has also been careful to keep his distance from the Reformists, as he tries to win votes from disillusioned conservatives as well.
On paper it is an attractive formula. The problem is that Mr Mousavi is not a great campaigner.
He is a grey figure, who will have trouble inspiring Iran's mainly young population to go out and vote.
The other two main candidates are Mehdi Karroubi, the only candidate to call himself "Reformist", and Mohsen Rezai, who comes from the opposite end of the political spectrum.
Both are seen as outsiders, but either of them could prevent the leading candidate getting an overall victory in the first round of the elections, on June 12, forcing a run-off a week later.
Campaigning formally begins on 21 May. It has already become an unusually personal campaign, and the tone is hardly likely to improve as polling day approaches.