But Ahmadinejad's landslide win over Rafsanjani, who was largely seen as the front-runner, marked a remarkable comeback.
Ahmadinejad had not been expected to even make it into the runoff, but he managed to pull off a surprising second-place finish in last week's balloting, putting him into the showdown with Rafsanjani.
Polls closed in the presidential runoff about 11:30 p.m. Friday (3 p.m. ET) after several extensions were issued to allow late voters to cast ballots.
Many analysts say Ahmadinejad's victory will deal a blow to those throughout the country who have fought for democratic and economic reforms -- even if supreme leader Ayatollah Ali Khameinei has the last word in matters of state.
The race between Rafsanjani and Ahmadinejad set up a striking choice for Iranians.
Rafsanjani had softened his stance in recent months, calling for improving Iran's strained ties with the West -- including the United States, which has had no formal diplomatic ties with the country since the 1979 Islamic Revolution.
Another defeat obtained from the jaws of victory by C-plus Augustus.