Iranians took a step toward ending their country’s isolation by voting overwhelmingly in weekend presidential elections for a moderate reformer who promised a clean break from policies that put Iran on a collision course with the West.

Millions of Iranians jammed polling stations across the country to hand a stunning victory to Hassan Rouhani, a Shiite cleric who campaigned on a pledge of “reconciliation and peace.” Rouhani, who had been considered a dark horse, blew past a slate of conservative candidates to win the presidency in the first round of voting, upsetting conventional wisdom and delivering an unmistakable rebuke to the country’s supreme leader, Ayatollah Ali Khamenei.

Although the election’s impact is far from clear, U.S. officials and Middle East observers welcomed the results as heralding a new chapter in ties between Iran and the West. Some saw increased hope for progress toward a diplomatic solution to the Iranian nuclear crisis, the most intractable and potentially dangerous dispute in Iran’s relations with the West.

“We respect the vote of the Iranian people and congratulate them for their participation in the political process, and their courage in making their voices heard,” White House press secretary Jay Carney said in a statement. Noting that the vote took place against the backdrop of censorship and an “intimidating security environment,” Carney said, “the Iranian people were determined to act to shape their future.”

News of Rouhani’s win touched off spontaneous street celebrations that transformed some of Tehran’s streets into parking lots. During voting on Friday, so many Iranians turned out at polling stations that voting hours had to be extended as many as four times, with some closing after 11 p.m.

When it was over, about 72 percent of Iran’s electorate had turned to vote in the election to replace the two-term president, Mahmoud Ahmadinejad.

The final results were confirmed in a televised announcement late Saturday by Interior Minister Mostafa Mohammad-Najjar, who declared Rouhani the outright winner with 50.7 percent of the votes, avoiding a runoff. The mayor of Tehran, Mohammad Bagher Ghalibaf, came in a distant second, with 16.6 percent of the vote. Saeed Jalili, Iran’s hard-line nuclear negotiator, came third with 11.4 percent. A handful of other conservative candidates fared poorly.

Iranian analysts said Rouhani apparently rode a wave of enthusiasm that materialized late in the contest, when supporters began sensing that the moderate could overcome a divided conservative field of candidates who campaigned on their close ties to the supreme leader and allegiance to his policies.

After the 2009 election, those results — which are still contested by opponents of Ahmadinejad — were announced on state television in the late evening, only a short time after ballot boxes closed, leading to suspicions about the accuracy of the count.

This time, Iran’s Interior Ministry took no chances, releasing the official vote total in live updates, which showed a steady increase in Rouhani’s margin of victory over Ghalibaf.

Until last week, Ghalibaf was widely considered the front-runner, but he likely lost votes to fellow conservative candidate Jalili.

In the end, though, it did not matter, as Rouhani took a majority of the votes, which is already being viewed as a repudiation of not only the Ahmadinejad years but also the hold that conservatives have maintained over Iranian politics since 2005.

Rouhani has pledged to bridge the divide between conservatives and reformists, and if his past record is any indication, he is well positioned to do so.

With the backing of former presidents Mohammad Khatami and Ali Akbar Hashemi Rafsanjani, Rouhani will have a powerful mandate to improve Iran’s international relations and attempt to negotiate a settlement of Iran’s nuclear activities.

“Rouhani is, as we say in Persian, more bazaari than resistance, meaning he’s more a dealmaker than a rigid ideologue,” said Karim Sadjadpour, an Iranian American and analyst for the Carnegie Endowment for International Peace, a Washington think tank. “It’s true that Iran’s existing foreign policy principles are pretty entrenched, but he may be able to impact them, at a minimum tactically.”

For Obama and his national security team, Rouhani represents “the best hope for detente with Iran,” he said.

Often referred to as the “diplomat sheik” in Iranian media, Rouhani led Iran’s nuclear negotiating efforts from 2003 to 2005, resigning the post after Ahmadinejad became president.

Rouhani has since been a harsh critic of Ahmadinejad’s economic and foreign policy.

Even before all the votes were counted, U.S. officials and Iran experts were seeing Rouhani’s strong showing as a positive development that could lead to a thaw in relations between Washington and Tehran. The moderate cleric has called publicly for ending Iran’s diplomatic isolation, telling a crowd at one campaign stop last week, “I’ll pursue a policy of reconciliation and peace.”

Rouhani’s late surge in the polls surprised many Washington observers, coming at the end of a lackluster campaign that appeared to have been tightly scripted to give an edge to conservatives close to Khamenei.

Ray Takeyh, a former State Department adviser and Middle East expert, said the results probably “even surprised Rouhani,” who appears to have been an unexpected beneficiary of pent-up resentments among Iranians after years of political repression and the recent economic hardships brought on by Western sanctions.

“This was supposed to be a well-regulated, well-crafted election, and then the wheels came off,” Takeyh said. “It appears that the leadership miscalculated on Rouhani’s appeal and also miscalculated on the ineptness of its preferred candidates and the impact of the divisions among the conservative coalition.”

Current and former administration officials have been cautious in predicting how the election would affect Iran’s nuclear policies, which are controlled primarily by Khamenei and the elite Revolutionary Guard Corps. But some said a landslide for Rouhani could force the country’s religious leaders to shift policies that have subjected Iran to international censure and harsh economic sanctions.

Rouhani probably will bring with him a cadre of more moderate diplomats, technocrats and nuclear negotiators who favor a more pragmatic foreign policy, said Trita Parsi, author of “A Single Roll of the Dice,” a book on the Obama administration’s dealings with Iran.

But whether the political shift leads to a deal to restrain Iran’s nuclear program depends on many factors, much outside the control of Iran’s new president, Parsi said.

“Ultimately the ball comes back to our side of the court,” Parsi said. “Neither side can break this impasse alone.”

Warrick reported from Washington.