Published: 2017-04-21 10:19:12 BdST
The approval of Rouhani, a moderate, and Raisi, a political hardliner thought to have the backing of Supreme Leader Ayatollah Ali Khamenei, sets up a showdown between rival political camps.
Four other candidates were also qualified to run. Among them are Rouhani's vice president, Eshaq Jahangiri, and Tehran Mayor Mohammad Baqer Qalibaf.
Khamenei had advised Ahmadinejad not to run, and his attempt to become a candidate was widely seen as a public snub to the Supreme Leader, which is nearly unheard of in the Islamic Republic.
The disqualification of Ahmadinejad, a two-term president, draws attention to the criteria that the Guardian Council, the governmental body which vets candidates, uses in the selection process.
Khamenei appoints half of the members of the Guardian Council, and by disqualifying Ahmadinejad, the body runs the risk of being seen as a rubber stamp for the Supreme Leader, who is the highest authority in the country.
Iran's President Hassan Rouhani gestures as he registers to run for a second four-year term in the May election, in Tehran, Iran, Apr 14, 2017. Reuters
Iran agreed to curb portions of its nuclear program in exchange for the lifting of several sanctions as part of the deal.
Political hardliners see the deal as a form of capitulation and are wary of the opening it presents for Western companies to work in the Islamic Republic.
In recent days, Raisi, who was appointed by Khamenei as the head of a multi-billion-dollar religious foundation last year, has repeatedly blasted Rouhani's economic performance.
Khamenei has also criticized Rouhani's economic performance in recent speeches and called on the government to do more to address the issue of unemployment.
About 3.2 million Iranian are jobless out of a total population of 80 million.
Rouhani has claimed that inflation has decreased and the economy has grown on his watch. He has also said in recent public appearances that the judiciary and security forces should be more mindful of ordinary Iranians' rights and privacy, which is likely to appeal to his supporters.
Iran's President Mahmoud Ahmadinejad talks during a news conference at the end of his visit to Cairo, Egypt Feb 7, 2013. Reuters
Regardless of how the rivalry between Rouhani and Raisi plays out, top Iranian officials, including Khamenei, have said they will confront any individuals or groups who attempt to destabilize the country.
Iranian police fanned out across Tehran after the names of the candidates were announced on Thursday night, according to the news site of the Iranian judiciary Mizan Online.
Live debates between presidential candidates, a feature in the last two presidential elections, have also been called off, according to state media. Pre-taped interviews will air instead, perhaps to keep candidates from stoking up their supporters.
Widespread protests broke out and continued for months after the disputed election of Ahmadinejad in 2009, and led to dozens of deaths and hundreds of arrests.
"The bitter incidents of (2009) will not be repeated," Tehran prosecutor Abbas Jafari Dolatabadi said on Wednesday, according to state media.