An Iranian woman flashes a victory sign as she waits to cast her ballot in the presidential elections at a polling station in Tehran on Friday.
Supreme Leader Ayatollah Ali Khamenei, Iran's most powerful man and decision maker, symbolically cast the importance of the election's first vote and asked Iranians to go out and vote.
Iranian authorities say they believe the vote will exceed a 70 percent turnout.
Of the 40 million ballots counted so far, Rouhani has secured 22.796 million votes, while Raisi has garnered 15.452 million, the official said at the briefing.
His challenger, conservative former prosecutor Ebrahim Raisi, received 10 million votes, while the other two candidates did not break through the 1 million mark.
Official final results are expected later on Saturday.
Iranian voters wait for a polling station to open during the presidential election in Tehran, Iran, May 19, 2017.
Shortly before polls were due to close, state television reported that voting had been extended by at least two extra hours to cope with a "rush of voters".
Raisi has tried to gain support by promising more financial support to the working class and to triple cash handouts to the poor.
But Iran's economy has not recovered as fast as Rouhani promised, sparking criticism of his government from conservatives close to Iran's supreme leader, Ayatollah Ali Khamenei.
Iranians living in Canada eager to cast ballots in Friday's all-important presidential election were forced to cross the border to vote in the USA, or not vote at all.
For the average Iranian, the results have been lackluster, and Raisi has jumped upon this accusing Rouhani of sacrificing Iran's sovereignty for a fool's bargain. He called for a large turnout, saying "the country is in the hands of all people".
Raisi's election would be seen as a rebuke of the nuclear deal and, as Suzanne Maloney of the Brookings Institution told the Huffington Post, while the deal wouldn't fall apart immediately, it would "erode nearly inevitably as a result of the lack of commitment from Iran" under Raisi.
Analysts have suggested that a high voter turnout will help Rouhani win a second four-year term.
Still, the election offers stark choices for Iranians on the direction of their country.
Iran's 56 million eligible voters can head to more than 63,000 polling places across the country.
All candidates for elected office must be vetted, a process that excludes anyone calling for radical change, along with most reformists. If no candidate wins an outright majority of Friday's vote, a runoff election between the top two finishers will be held next week. The rest of the candidates trailed far behind Rouhani and Raisi, with Mostafa Mirsalim getting 455,211 votes and Mostafa Hashem Taba 210,597 votes at the latest count.