Iran's former President Mahmoud Ahmadinejad on Wednesday unexpectedly filed to run in the country's May presidential election, contradicting a recommendation from the supreme leader to stay out of the race.

Mr. Ahmadinejad's decision will upend an election many believed would be won by moderate President Hassan Rouhani, who negotiated the nuclear deal with world powers. Though Mr. Rouhani has yet to formally register, many viewed him as a shoe-in following Supreme Leader Ayatollah Ali Khamenei's recommendation in September for Ahmadinejad to stand down.

But many hard-liners in Iran seek a tough-talking candidate to rally around who can stand up to US President Trump. Ahmadinejad's candidacy also could expose the fissures inside Iranian politics that linger since his contested 2009 re-election, which brought massive unrest.

Associated Press journalists watched as stunned election officials processed Ahmadinejad's paperwork on Wednesday.

Asked about Ahmadinejad's decision, one Tehran-based analyst offered a blunt assessment.

"It was an organized mutiny against Iran's ruling system," said Soroush Farhadian, who backs reformists.

Ahmadinejad 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 polarizing figure, even among fellow hard-liners.

Two of his former vice presidents have been jailed for corruption since he left office. 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 program is for peaceful purposes.

Ahmadinejad's disputed re-election in 2009 sparked massive protests and a sweeping crackdown in which thousands of people were detained and dozens were killed.

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

The memory of the 2009 unrest likely sparked Mr. Khamenei's comments in September. At that time, he recommended an unnamed candidate not seek office as it would bring about a "polarized situation" that would be "harmful for the county."

Ahmadinejad described comments by the supreme leader suggesting he not run as "just advice" in a news conference shortly after submitting his registration. There was no immediate reaction from the supreme leader's office.

He said his decision to run was intended to help former Vice President Hamid Baghaei, a close confidant. Baghaei registered alongside Ahmadinejad on Wednesday, as did Esfandiar Rahim Mashaei, another of the former president's close allies.

More than 120 prospective candidates submitted their names as candidates on the first day of registration Tuesday, including six women and seven clerics. Registration remains open until Saturday.

Under Iran's electoral system, all applicants must be vetted by the Guardian Council, a clerical body that will announce a final list of candidates by April 27. The council normally does not approve dissidents or women for the formal candidate list.

Get the Monitor Stories you care about delivered to your inbox. By signing up, you agree to our Privacy Policy

The May 19 election is seen by many in Iran as a referendum on the 2015 nuclear agreement with world powers and its ability to improve the country's sanctions-hobbled economy. Under that deal, Iran agreed to curb its uranium enrichment in exchange for the lifting of international sanctions.

Since the deal, Iran has signed multi-billion-dollar contracts with airplane manufacturers Boeing Co. and Airbus. The benefits have yet to trickle down to the average Iranian, however, fueling some discontent.