IRAN'S former president Mahmoud Ahmadinejad has filed to run in the country's May presidential election, defying a recommendation from the nation's Supreme Leader to stay out of the race.

Surprised election officials processed his paperwork yesterday, as he had previously said he would not run, after Supreme Leader Ayatollah Ali Khamenei advised him not to.

However, many hard-liners in Iran want a tough-talking candidate to stand up to US President Donald Trump.

Iran's moderate President Hassan Rouhani, who negotiated Tehran's nuclear deal with world powers, is expected to run for re-election.

Ahmadinejad said the recommendation by Ayatollah Khamenei was "just advice", as he registered alongside his former vice-president Hamid Baghaei, a close confidant.

His decision to run will upend an election many believed would be won by Rouhani.

Ahmadinejad's candidacy also could expose the fissures inside Iranian politics that have lingered since his contested 2009 re-election, which brought massive unrest.

He previously served two four-year terms from 2005 to 2013. Under Iranian law, he became eligible to run again after four years out of office, but he remains a polarising figure, even among fellow hard-liners.

Two of his former vice-presidents have been jailed for corruption since he left office, and Iran's economy suffered under heavy international sanctions during his administration because of Western suspicions that Tehran was secretly pursuing nuclear weapons. Iran insists its nuclear programme is for peaceful purposes.

His disputed re-election in 2009 sparked massive protests and a sweeping crackdown in which thousands of people were detained, dozens killed and others tortured.

Internationally, he is more known for repeatedly questioning the scale of the Holocaust, predicting Israel's demise and expanding Iran's nuclear programme.

The memory of the 2009 unrest is thought to have sparked Ayatollah Khamenei's comments in September. At the time, he recommended an unnamed candidate not seek office as it would bring about a "polarised situation" that would be "harmful for the country".