TEHRAN, Iran (AP) — Iran's former President Mahmoud Ahmadinejad on Wednesday stunned the country by unexpectedly filing to run in the May presidential election, contradicting a recommendation from the supreme leader to stay out of the race.

Ahmadinejad's decision could upend an election many believed would be won by moderate President Hassan Rouhani, who negotiated the nuclear deal with world powers. Though 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 and conservatives' inability to coalesce around a single candidate.

Ahmadinejad's firebrand style could prove appealing for hard-liners seeking a tough-talking candidate who can stand up to U.S. President Donald Trump. His 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.

Story continues

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 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.

"His advice does not prevent me from running," he said. "There is extensive pressure on me from dear people of different walks of life as their small servant to come to the election."

There was no immediate reaction from the supreme leader's office.

Ahmadinejad said his decision to run was intended to help former Vice President Hamid Baghaei, a close confidant. Baghaei, who was imprisoned for seven months after he left office, registered alongside Ahmadinejad on Wednesday. So 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.

The May 19 election is seen by many in Iran as a referendum on the 2015 nuclear agreement and other efforts to improve the country's sanctions-hobbled economy. Under the nuclear 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.

Related Video:

For more news videos visit Yahoo View, available now on iOS and Android.

___

Gambrell reported from Dubai, United Arab Emirates. Associated Press writer Adam Schreck in Dubai contributed to this report.