By Asa Fitch and Aresu Eqbali

TEHRAN, Iran -- Moderate Iranian President Hassan Rouhani won re-election by a wide margin Saturday, defeating a hard-line challenger and getting an endorsement for efforts to seek better ties with the West and attract foreign investment to bolster the economy.

In his first term, Mr. Rouhani negotiated a 2015 deal with the U.S. and five other world powers to curb Iran's nuclear program in exchange for an easing of sanctions. During the campaign he pledged to work to have remaining sanctions against Iran lifted as he fights slow growth and high unemployment.

That task could be difficult with President Donald Trump in the White House. Mr. Trump, who before his election promised to rip up the nuclear agreement, is reviewing his administration's Iran policy and said in April that Iran wasn't living up to the spirit of the deal.

On Saturday, Mr. Trump started a visit to Saudi Arabia, the first stop on his first trip abroad as president, a sign of warming U.S. ties with Iran's most important regional rival. Saudi Arabia leads a Sunni Muslim alliance aimed at blunting the influence of Shiite Iran.

Mr. Rouhani scored a major victory over Ebrahim Raisi, a conservative cleric and judge close to Iranian Supreme Leader Ayatollah Ali Khamenei. Mr. Rouhani received 57% of the vote, Iran's Interior Ministry said. Mr. Raisi took 38.5%. The rest of the vote was split between two minor candidates.

It was a significantly bigger margin than Mr. Rouhani managed in 2013 when he was elected to his first term with 51%.

In a televised address, Mr. Rouhani highlighted the first-term agenda that swept him back into office and promised more progress in the coming four years.

"Today, the world knows well that the Iranian nation has chosen the path of engagement with the world without violence and extremism, while it is not willing to accept humiliation or threat," he said. "This is the most important message that our nation expects to be heard properly by all governments, neighbors and especially big world powers."

But in Iran's unique political system, where Mr. Khamenei has final say over state matters and limits the president's power, Mr. Rouhani's convincing victory may not translate into a mandate, according to Ali Vaez, a senior Iran analyst at the Brussels-based International Crisis Group.

"Rouhani's ability to advance his agenda is more a function of his ability to build elite consensus than his margin of victory," he said.

U.S. Secretary of State Rex Tillerson on Saturday said he hopes Mr. Rouhani's re-election would prompt changes to Tehran's approach to terrorism and human rights.

Mr. Tillerson, speaking at a news conference with Saudi Foreign Minister Adel al Jubeir, said such a shift would improve Iran's relations across the world.

"What I would hope is that Rouhani now has a new term and that he use that term to begin a process of dismantling Iran's network of terrorism, dismantling its financing of that terrorist network, dismantling the manning and the logistics and everything they provide to these destabilizing forces that exist in this region," Mr. Tillerson said.

This year's race offered Iranians the choice between two starkly different visions: a technocratic government open to mutually beneficial interaction with the world versus an inward-facing emphasis on self-reliance coupled with populist appeal.

The margin of Mr. Rouhani's win surprised some who saw Mr. Khamenei's acceptance of the vote and Mr. Raisi's loss as an acknowledgment of asea change in Iranian attitudes. Iran's population skews young, and many in the new generations want to improve Iran's image and embrace cultural freedoms.

"Khamenei has to smell the coffee -- Iran wants to live in the future of Rouhani, not in the stone age of [former hard-line President Mahmoud] Ahmadinejad," said Cliff Kupchan, the chairman of political risk consultancy Eurasia Group. "The leader is ideological, but the size of the win and the fact that he let it stand shows he's at least beginning to get it."

Despite Mr. Khamenei's presence atop Iran's system, presidents are powerful figures who help put in place policies approved by the leader and craft how Iran presents itself to the world. Mr. Khamenei didn't endorse either candidate, though he was critical of Mr. Rouhani's government in the months before the election, complaining about double-digit unemployment and calling for a boost in exports.

Meanwhile, since Mr. Trump took office, the U.S. has slapped two rounds of new sanctions on Iran related to its ballistic missile program. Mr. Rouhani has defended Iran's ballistic missile program, asserting that it is for defensive purposes only.

Mr. Rouhani, however, has no control over the missile program. It is managed by the Islamic Revolutionary Guard Corps, a force that reports directly to Mr. Khamenei. During the second of three presidential debates, Mr. Rouhani criticized the IRGC's test-firing of a missile emblazoned with a slogan calling for Israel's elimination shortly after the nuclear deal took effect.

For Israel and the U.S. and its Arab allies, the election didn't appear likely to alter distrust of Iran's activities in the region. Iran is the main military and financial backer of Syrian President Bashar al-Assad, putting it at odds with U.S. regional policy. It also props up Shiite Muslim militias in Iraq and Hezbollah in Lebanon, a militant group the U.S. has long branded a terrorist organization.

Mr. Rouhani has said he wants to push ahead with attempts to fix his country's economic woes by building trade ties and developing industries at home with help from outside.

French auto makers Renault, Peugeot and Citroën have announced ventures in the country. Boeing Co. and Airbus SE are selling Iran tens of billions of dollars in planes to revamp an aging fleet.

After sowing the seeds in his first term, Mr. Rouhani now has the chance to reap the rewards, said Amir Hossein Karimi, a 25-year-old student who volunteered in both of the president's campaigns. He played down Mr. Trump's effect on his plans.

"There are lots of options on the table, but most of them are costly, like war," he said. "I think Trump is a clever man and he won't choose war."

Mr. Raisi, a cleric who served for decades in Iran's opaque judiciary and was appointed by Mr. Khamenei lastyear as custodian of a multibillion-dollar charity in the holy city of Mashhad, sought to capitalize on the lagging economy. He promised to triple cash handouts for the poor and revive a financially troubled low-income housing project.

Mr. Raisi's increased political prominence suggested he was in the running to succeed the 77-year-old Mr. Khamenei, who has had health problems. With the election loss, Mr. Kupchan said his political career was probably over.

Mr. Raisi acknowledged his loss in a statement on his official website. He wished Mr. Rouhani success and said he would to fight corruption.

Mohmmad Reza Samadi, 19, an electrical engineering student who voted for Mr. Raisi, said he accepted the outcome even if he wasn't happy with it.

"He will go on with the position he has in Mashhad," he said. "So why not come back for the next election?"

Iran's Guardian Council, a vetting body closely overseen by Mr. Khamenei, determined who could appear on the ballot for this election, as it has in the past. The council approved six candidates. Two dropped out, leaving Mr. Rouhani and Mr. Raisi as the only serious contenders.

Write to Asa Fitch at asa.fitch@wsj.com

(END) Dow Jones Newswires

May 20, 2017 13:34 ET (17:34 GMT)

Copyright (c) 2017 Dow Jones & Company, Inc.