TEHRAN — Riding a large turnout from Iran’s urban middle classes, President Hassan Rouhani won re-election in a landslide on Saturday, giving him a mandate to continue his quest to expand personal freedoms and open Iran’s ailing economy to global investors.
Perhaps as important, analysts say, the resounding victory should enable him to strengthen the position of the moderate and reformist faction as the country prepares for the end of the rule of the 78-year-old supreme leader, Ayatollah Ali Khamenei.
With most of the votes from Friday’s election counted, the Interior Ministry said Mr. Rouhani had won 22.8 million, soundly defeating his chief opponent, Ebrahim Raisi, who received 15.5 million. Iranian state television congratulated Mr. Rouhani on his victory.
Turnout was heavy, with about 40 million of Iran’s 56 million voters, more than 70 percent, casting ballots.
Despite the healthy margin of victory, Mr. Rouhani, 68, will face considerable headwinds, both at home and abroad, as he embarks on his second term.
He badly needs to demonstrate progress on overhauling the moribund economy. While he accomplished his goal of reaching a nuclear agreement with the United States and Western powers in his first term, that has not translated into the economic revival he predicted because of lingering American sanctions.
He 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. Rouhani, who has managed to mend ties with the European Union, is undaunted, saying only last week that, “We will break all the sanctions against Iran.”
He has some cards to play with the United States. Iran provides crucial support to the government of Prime Minister Haider al-Abadi in Iraq — an American ally — and any effort to roll back Iranian influence there and in Syria could jeopardize efforts to retake the cities of Mosul and Raqqa from the Islamic State extremist group.
Mr. Raisi, a hard-line judge who leads one of the wealthiest religious foundations in the Middle East, campaigned as a corruption fighter and called on Iran to solve its economic problems without help from foreigners. He appealed primarily to poor and deeply religious Iranians, many of whom felt left out of Mr. Rouhani’s vision for the future.
While he was soundly beaten, analysts said Mr. Raisi fared well enough to maintain his status as a potential successor to Ayatollah Khamenei.
In defeating Mr. Raisi, Mr. Rouhani proved once again that Iran’s electorate prefers the moderate reformist path over the rigid ideology and harsh social restrictions favored by the conservative clergy and security establishment.
Despite controlling most unelected councils, the conservative clerics and Revolutionary Guard commanders — backed by state television — have suffered a string of political defeats, starting with Mr. Rouhani’s election in 2013. That led to direct talks with their archenemy, the United States, and ultimately to the nuclear deal, which they opposed. Then moderate and reformist candidates made strong gains in last year’s parliamentary elections.
Nevertheless, as supreme leader, Ayatollah Khamenei remains the ultimate arbiter in Iran’s opaque political system, and he must approve any further changes sought by Mr. Rouhani.
Yet, the supreme leader has demonstrated a surprising flexibility in recent years. While he publicly defends the hard-liners, he has permitted Mr. Rouhani to break some decades-old ideological canons when public pressures grow too intense.
Thus, most Tehran residents have satellite dishes that enable them to watch foreign news broadcasts and entertainment, and couples often walk hand-in-hand through the city’s parks without fear of arrest or harassment.
As much a victory for Mr. Rouhani and his team, the election result also reflects the political coming-of-age of urban Iranians who voted in high numbers to thwart the candidacy of Mr. Raisi, whom they viewed as a second coming of the Holocaust-denying former president, Mahmoud Ahmadinejad.
Progressive Iranians had vowed not to repeat the mistake they made in 2005, when many of them boycotted that year’s election out of disillusionment with the hard-liners’ thwarting of the reformist agenda of the outgoing president, Mohammad Khatami. That allowed the Islamic Revolutionary Guard Corps and conservative clerics to elect Mr. Ahmadinejad, who poisoned relations with the West.
This time, prominent intellectuals, actresses, Instagram stars and sports figures waged social media campaigns to urge people to go out and vote for Mr. Rouhani.
One of those, Reihane Taravati, 26, who has 175,000 followers on Instagram, achieved a measure of fame in 2014 when she and some friends were arrested after making a video of them dancing to the song ‘Happy’ by the American rapper Pharrell.
She was sentenced to 91 lashes and jail time, though the rulings were later suspended. “At the time, Mr. Rouhani tweeted saying the country needed happiness,” she said. “That was a great help.”
This year, she decided she wanted to help Mr. Rouhani win re-election.
“I looked at what he has achieved for us in the past four years and decided I had to do something”, she said in an interview over the messenger app Telegram.
The nuclear deal has been hugely important in bringing Iran with all its talented young people out of its isolation, she said. “But what he has done for the internet has been revolutionary. He increased the speed and now we no longer need state television as a platform. We are our own media now.”
So Ms. Taravati opened up her Instagram account and started posting pictures in support of Mr. Rouhani. “We do not want to lose what we have gained and his win is a big victory,” she said.
Over the past week of campaigning, streets in Iranian cities were filled with supporters of both candidates, often friendly but at times arguing over the future of the country.
The election campaign emphasized a split between those favoring an overhaul of the quasi-socialist economy and expanded personal freedoms and those wanting to adhere to the ideological precepts of the Islamic Revolution of 1979.
“I am voting for Raisi because he is a ‘seyed,’” said Fazlolah Bahriye, using the honorific given to those believed to be descendants of the Prophet Muhammad. Mr. Bahriye, who said he thought he was in his early 70s (many in Iran are unsure of their birth dates), then offered a diatribe against politicians, saying that they promised many things but never delivered.
Other voters, especially younger ones, said they favored Mr. Rouhani. “I want more freedom, a relaxation of the strict rules,” said Muhammad Badijan, 19. He was wearing bright blue contact lenses that matched his shirt. “I just want to live a normal life,” he added.
In the end, analysts said, the biggest impact of Mr. Rouhani’s victory will be felt if Ayatollah Khamenei, who has had some health issues in recent years, should die or step down.
“A big margin victory, and god forbid the supreme leader passes in the coming four years, Rouhani will, at least temporarily have a better command to run the country,” said Fazel Meybodi, a Shiite Muslim cleric from the city of Qum, and a supporter of Mr. Rouhani.
“Of course in the long term it is the Expert Assembly that will decide,” he said of the 86 member council that will choose the next leader. “But Mr. Rouhani will be more influential there, after this victory,”