With nearly 97 percent of more than 16.7 million ballots counted, Rouhani had 50.5 percent of the vote, Press TV reported Saturday.
Rouhani, a centrist, will replace incumbent Mahmoud Ahmadinejad, who was barred from seeking re-election because of term limits.
Campaigning began May 22 with eight candidates approved by the Guardian Council. Two candidates withdrew, one only three days before the election on Friday.
Some 50.5 million people were eligible to vote in the election, the interior ministry said, including 1.6 million youths who were eligible to vote for the first time.
Voting took place in the country's 66,285 polling stations and 96 countries around the world.