TEHRAN, Iran (AP) — Wild celebrations broke out on Tehran streets that were battlefields four years ago as reformist-backed Hasan Rowhani capped a stunning surge to claim Iran’s presidency on Saturday, throwing open the political order after relentless crackdowns by hard-liners to consolidate and safeguard their grip on power.

“Long live Rowhani,” tens of thousands of jubilant supporters chanted as security officials made no attempt to rein in crowds — joyous and even a bit bewildered by the scope of his victory with more than three times the votes of his nearest rival.

In his first statement after the results were announced, Rowhani said that “a new opportunity has been created … for those who truly respect democracy, interaction and free dialogue.”

But in Iran, even landslides at the ballot box do not equate to policymaking influence.

All key decisions — including nuclear efforts, defense and foreign affairs — remain solidly in the hands of the ruling clerics and their powerful protectors, the Revolutionary Guard. What Rowhani’s victory does is reopen space for moderate and liberal voices that have been largely muzzled in reprisal for massive protests and clashes in 2009 over claims the vote was rigged to deny reformists the presidency.

Rowhani’s supporters also viewed the election as a rebuke of uncompromising policies that have left the Islamic Republic increasingly isolated and under biting sanctions from the West over Tehran’s nuclear program. The 64-year-old Rowhani is hardly a radical — having served in governments and in the highly sensitive role of nuclear negotiator — but he has taken a strong stance against the combative international policies of outgoing President Mahmoud Ahmadinejad and others.

“I’ve never been an extremist,” Rowhani said on state TV shortly after the official results were announced. “I support moderation.”

“I thank God that once again rationality and moderation has shined on Iran,” he continued. “This is the victory of wisdom, a victory of moderation and a victory of commitment over extremism.”

His emphasis on outreach could sharply lower the political temperature between Iran and the West — including Israel — and perhaps nudge the ruling establishment toward more flexible approaches in possible renewed nuclear talks with the U.S. and world powers. Rowhani also has added leverage with his political godfather and ally, former President Akbar Hashemi Rafsanjani, who was blocked from the ballot but now can exert significant influence from the wings.

Alireza Nader, a senior policy analyst at the Rand Corp. who follows Iranian affairs, described Rowhani as a de facto hero for reformists who couldn’t support any of the other five candidates on the ballot.

“It remains to be seen how much room will be given to Rowhani by Supreme Leader Ayatollah Ali Khamenei and the Revolutionary Guard,” he cautioned.

But clearly for Iran’s leadership, the resounding strength of Rowhani’s victory underscores the resilience and reach of the opposition that coalesced four years ago around the now-crushed Green Movement.

In the divided country, it also may provide a bit of buffer. The outcome could ease some of the opposition anger and be used by the ruling clerics to try to bolster their image and legitimacy.

“They counted my vote, they counted my vote,” some supporters sang in reference to the protest slogan of four years ago: “Where is my vote?”

On social media, many supported quickly posted images mixing the Green Movement colors with the signature purple of Rowhani’s campaign with the boast: “We won!”

Some cried: “Ahmadinejad, bye bye.”

Others chanted slogans not heard openly on Iran’s streets for years: calling for the release of political prisoners including Green Movement leader Mir Hossein Mousavi and opposition figure Mahdi Karroubi, both candidates in 2009 and both under house arrest.

“It’s the spring of freedom, too bad Neda isn’t here,” some yelled in memory of Neda Agha Soltan, a young woman fatally shot during the 2009 unrest and whose dying moments — posted on the Web — became an enduring symbol of the bloodshed.

Just a week ago, Rowhani — the only cleric in the race — seemed greatly overshadowed by candidates with much deeper ties to the ruling theocracy and Revolutionary Guard, including hard-line nuclear negotiator Saeed Jalili and Tehran Mayor Mohammad Bagher Qalibaf. Many reformists, demoralized by Rafsanjani’s rejection by election overseers, planned to boycott.

But Rowhani gained momentum: first with endorsements from Rafsanjani and another moderate-minded former president Mohammad Khatami. Then artists, activist and opposition leaders joined. In the span of a few days, Rowhani was drawing huge crowds and the race — once seen as firmly in the control of the ruling system — was suddenly transformed.

The size of the groundswell even appeared to put Iran’s election authorities off balance. Partial results were released in a slow drip over the day even as Rowhani’s supporters both basked in the lead and nursed lingering fears from the alleged vote-rigging in 2009.

In the end, Rowhani narrowly cleared the margin that would have forced a two-candidate runoff. The Interior Ministry said Rowhani took 50.7 percent of the more than 36 million votes cast, well ahead of Qalibaf with about 16.5 percent. Jalili — who said he was “100 percent” against detente with Iran’s foes — came in third with 11.3 percent, followed by conservative Mohsen Rezaei with 10.6 percent.

Interior Minister Mostafa Mohammad Najjar said the turnout was 72.7 percent, suggesting that liberals and others abandoned a planned boycott as the election was transformed into a showdown across the Islamic Republic’s political divide. Iran has more than 50 million eligible voters.

“After weeks of speaking and hearing, it’s time to work,” Khamenei said on state TV, which gave no mention of street celebrations.

The White House congratulated Iranian voters for “their courage in making their voices heard” despite clampdowns that included severe restrictions on the Internet, a key tool of Iran’s opposition. Washington urged Tehran’s leadership to “heed the will of the Iranian people and make responsible choices,” while noting the U.S. remained open for direct dialogue with Iran.

U.S. Secretary of State John Kerry said Rowhani now has the opportunity to keep his promises to the Iranian people “to restore and expand freedoms for all Iranians.”

The Israeli Foreign Ministry issued a statement with a reminder that Khamenei and his inner circle control Iran’s nuclear program and “Iran will continue to be judged by its actions, in the nuclear sphere as well as on the issue of terror.”

Israel has led accusations that Iran could secretly be trying to develop an atomic weapon, and has warned a military option is possible if negotiations with world powers go nowhere. Israel also strongly condemns Tehran for its backing of anti-Israel Islamic militant groups such as Hezbollah and Hamas in the Gaza Strip.

Iranian officials, including Rowhani, insist the country’s nuclear efforts are only for energy and medical purposes.

While the nuclear issues are ultimately under the wide powers of the ruling clerics, one of the top duties of Iran’s president is guiding the economy.

This could quickly become a huge burden for Rowhani’s government with new U.S. sanctions set to take effect July 1 — about six weeks before he officially takes over.

Western sanctions have shrunk vital oil sales and left the country isolated from international banking systems. The new American measures will further target Iran’s currency, the rial, which has lost half its foreign exchange value in the past year, driving prices of food and consumer goods sharply higher.

The election result gave an immediate boost in a rare show of optimism. Tehran’s stock exchange index rose 2 percent while the rial strengthened 9 percent against the U.S. dollar.

The street celebrations also put an emphatic stamp on the end of Ahmadinejad’s eight-year era.

He leaves office weakened and humbled after attempts to encroach on the powers of Khamenei and the ruling clerics. He has been quiet on his future, but options remain open to start a political movement and seek a comeback in the future.

“Rowhani who has won the trust of the majority of the nation,” Ahmadinejad said in a message that appeared to hint about his own political troubles. “I hope … the opportunity will be provided, more than before, to serve and work for justice and the development of the country.”