With all ballots counted, conservative Rafsanjani had more than 6.1 million votes, while the harder-line conservative Ahmadinejad had 5.7 million, Iranian state-run radio and television announced Saturday. The top two candidates face each other Friday.

Reformist cleric Mehdi Karroubi trailed in third place with nearly 5.1 million votes.

The conservative former police chief Mohammad Baqer Qalibaf and reformist Mostafa Moin followed in fourth and fifth respectively with more than 4 million votes.

About 31 million people -- nearly two-thirds of eligible voters -- took part in Friday's election. Of their ballots, 1.2 million were thrown out because they were "spoiled," the government said.

While Iran's U.N. Ambassador Javad Zarif called the turnout "better than expected," it was lower than in previous presidential elections.

When Rafsanjani and Ahmadinejad face each other Friday, they'll offer Iranian voters two strikingly different perspectives.

Rafsanjani, a conservative, has taken softer stances in recent months. He's expressed a desire to improve Iran's strained ties with the West -- including the United States, which has had no formal diplomatic ties with Iran since its 1979 Islamic Revolution.

In 2002 President Bush termed Iran part of an "axis of evil," along with North Korea and Iraq, then under Saddam Hussein.

Ahmadinejad, a hard-line conservative, has called for embracing the principles of the revolution. He has much support among vigilantes and popular militias, as well as poor people. He wants to turn some cultural institutions, created in recent years, back into mosques.

The outcome of the election is not expected to change Iran's theocratic government. Supreme leader Ayatollah Ali Khameinei still has the last word in matters of state.

Many of President Mohammed Khatami's initiatives were blocked by clerical hard-liners who hold vast power under Iran's Islamic government.

The reform-minded cleric is barred from seeking a third consecutive term.

CNN's Christiane Amanpour and Shirzad Bozorgmehr contributed to this report.