But no matter how large and sweeping any victory might be, Mr. Rouhani, 68, will face considerable headwinds, both at home and abroad.
While he accomplished his goal of reaching a nuclear agreement with the United States and Western powers, Iran has not enjoyed the economic benefits he predicted because of lingering American sanctions. He badly needs to demonstrate progress on overhauling the moribund economy.
Whoever wins must also deal with an unpredictable and hawkish Trump administration that this week only reluctantly signed the sanctions waivers that are a central element of the nuclear agreement. At a summit meeting this weekend in Saudi Arabia between President Trump and leaders of predominantly Muslim countries, Iran was pointedly not invited.
The Trump administration’s national security officials are on record as considering Iran the source of most of the Middle East’s troubles, while the Republican-controlled Congress is not about to loosen the unilateral sanctions that are frightening off foreign banks and businesses.
Mr. Raisi, 56, is a hard-line judge who campaigned as a corruption fighter and called on Iran to solve its economic problems without help from foreigners. He presented himself as a champion of the poor and the pious.
Urban Iranians voted in high numbers, largely against him.
Responding to campaigns on social media led by prominent intellectuals, actresses, Instagram stars and sports figures, about 40 million of the 56 million Iranians who live in or near cities turned out to vote.