Out of 25.9 million votes counted, Rouhani had 14.6 million and his hardline challenger Ebrahim Raisi 10.1 million, said Ali Asghar Ahmadi on state television.
Signup to our newsletter and follow us on Facebook and Twitter!
A huge turnout on Friday -- estimated at more than 40 million out of 56 million registered voters -- led to the vote being extended by several hours to deal with long queues.
Rouhani, a 68-year-old moderate cleric who spearheaded a 2015 nuclear deal with world powers, has framed the vote as a choice between greater civil liberties and "extremism".
But he has faced stiff competition from hardline cleric Ebrahim Raisi, 56, who positioned himself as a defender of the poor and called for a much tougher line with the West.