Police forces were sent out to the streets of Tehran, following the announcement of the Guardian Council on the list of accepted presidential race candidates. It carried an Interior Ministry statement saying that Rouhani has been approved to run for re-election.
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.
Rouhani, also a lawyer, is the seventh president of Iran since the 1979 Islamic revolution.
The Iranian vetting body (the GC) had examined the qualifications of more than 1,600 individuals who had submitted their names for registration as candidates in the upcoming presidential election slated for May 19.
Iranian reformists, led by former President Mohammad Khatami, have endorsed Rouhani, whose hardline rivals say he has failed to revive the economy despite sanctions being lifted.
Campaigning, which the Guardian Council announced could begin immediately, had not been supposed to start for another week, so there was little activity on Friday.
Khamenei has said Ahmadinejad candidacy would create a "polarized situation" that would be "harmful for the county".
The other candidates selected were hardliners Ebrahim Raisi and Mohammad Bagher Ghalibaf, conservative Mostafa Mirsalim, former minister Mostafa Hashemitaba and Mr Rouhani's ally and vice-president, Eshaq Jahangiri.
Some Iranian politicians believe Raisi is being groomed to succeed Khamenei and the presidency is just a first step.
Iran agreed to curb portions of its nuclear program in exchange for the lifting of several sanctions as part of the deal.
A close ally of Khamenei, Raisi is seen as the main hardline candidate challenging Rouhani in the election. Many hard-liners have rallied around Raisi, who got a boost past year when Khamenei appointed him head of an Islamic charity that holds extensive business interests in Iran. The current supreme leader was himself president (1980-1989) before being elevated to the regime's indisputably most powerful position, and a victory for Raisi would likely strengthen his own chances to become supreme leader.
He now serves as custodian of one of Iran's most important endowments, a position appointed by and answerable to the supreme leader.