Iran's former hardline President Mahmoud Ahmadinejad took the shock move on Wednesday of registering for next month's presidential election, going against the advice of the supreme leader.

Ahmadinejad had previously insisted he would not run after Ayatollah Ali Khamenei said last year that his candidacy would have a "polarizing" effect on the nation, and instead backed his ex-deputy Hamid Baghaie.

But the former president — whose tenure between 2005 and 2013 saw mass protests at home, plummeting relations with the West and a shattered economy — surprised everyone when he registered along with Baghaie on Wednesday.

He told reporters at the interior ministry, where registration was taking place, that he remained committed to his "moral promise" to Khamenei of not running for the May 19 election.

But he said Khamenei's "advice was not a ban."

"I repeat that I am committed to my moral promise and my presence and registration is only to support Mr. Baghaie," he added without explanation.

Only last week, flanked by his former deputy at his first press conference in four years, Ahmadinejad said he had "no plans to present myself. I support Mr. Baghaie as the best candidate."

The formal registration period for presidential hopefuls began on Tuesday and will continue until Saturday evening, after which candidates are vetted by the conservative-dominated Guardian Council, with a final list to be announced on April 27.

So far, 197 people have registered to run in the May 19 vote, eight of them women. No woman has ever been allowed to stand for the presidency in the Islamic republic.

End for Ahmadinejad?

Ahmadinejad lost the support of many mainstream conservatives during his contentious presidency, and some said on Wednesday that violating the supreme leader's advice was a final straw.

"With today's move — registering for the presidential election, my belief in you was broken," ex-lawmaker and Ahmadinejad loyalist Mehdi Koochakzadeh wrote on social media.

"End of Ahmadinejad," tweeted Elyas Naderan, another conservative former lawmaker.

Analyst Farzan Sabet, a fellow at the Center for International Security and Cooperation in Stanford University, said his registration was indeed "shocking".

But his motivation "may be to send an implicit threat to the Guardian Council that if they disqualify Baghaei — like they did his former chief-of-staff Esfandiar Rahim Mashaei in the 2013 presidential election — he will go back on his pledge and run for president," said Sabet.

He added that the Guardian Council would find it hard to disqualify Ahmadinejad, a two-time president who previously had the firm support of conservatives and the supreme leader.

"Although it is quite possible that Ahmadinejad will be disqualified by the Guardian Council, this could turn out to be politically messy for them," said Sabet.

The conservatives have been struggling to unite around a single candidate to challenge President Hassan Rouhani, who is expected to register in the coming days.

They held a mass meeting last week at which they shortlisted five candidates, who will be narrowed down to one before the vote, although some conservatives have already suggested they will run independently.

Ebrahim Raisi, a judge who currently heads the powerful Imam Reza charitable foundation in the Shiite Muslim holy city of Mashhad, topped the shortlist.

Tehran Mayor Mohammad Bagher Ghalibaf was also on the list, but it remains unclear if he will make his third bid for the presidency.

Rouhani has stabilised the economy and ended some sanctions through a 2015 nuclear deal with world powers.

But many Iranians are frustrated by the continued lack of investment in the economy and a jobless rate that remains at 12 percent.

Rouhani's administration argues it inherited a devastated economic landscape — the result of Ahmadinejad's populist policies that included monthly cash handouts and ill-fated housing projects.

But these policies have also ensured Ahmadinejad, 60, retains considerable popularity, particularly among the poor, potentially undermining attempts by conservatives to unite their base around a mainstream candidate.

If Ahmadinejad is allowed to run, "he would likely draw more votes away from conservative candidates than from Rouhani," said Sabet.

By AFP's Ali Noorani in Tehran.