Supporters of moderate cleric Hassan Rohani hold a picture of him as they celebrate his victory in Iran's presidential election on a pedestrian bridge in Tehran June 15, 2013. Reuters/Fars News/Sina Shiri

Handily thumping a passel of ultra-conservative politicians—including Saeed Jalili, Iran’s current chief nuclear negotiator, who won just 11 percent of the vote—Hassan Rouhani, a moderate cleric, garnered a stunning victory in Iran’s June 14 presidential election. He’ll take over from the erratic and bombastic Mahmoud Ahmadinejad in August.

Rouhani has close ties to the country’s reformist bloc, but he’s also a political insider: he served as national security adviser to President Ali Akbar Hashemi Rafsanjani (1989–97) and then worked closely with President Mohammad Khatami (1997–2005), serving as his chief negotiator in nuclear talks with Britain, France and Germany. Both Rafsanjani, the shrewd billionaire businessman who has long wanted to end Iran’s economic isolation, and Khatami, the godfather of the reformists, endorsed Rouhani just days before the vote, signaling to reform-minded Iranians, including those in the Green movement, that he should be their standard-bearer.

As he cast his ballot, Rouhani left no doubt that he saw himself as challenging Iranian hardliners head-on. “I have come to destroy extremism,” he said. During his campaign and in a triumphant post-election news conference, Rouhani said that Iran must abandon the counterproductive, confrontational course pursued by Ahmadinejad, seek better relations with the United States and strike an equitable deal over Iran’s nuclear program. But calling US-Iran enmity “an old wound that must be treated,” Rouhani also said he would insist that any deal be balanced. “America must not interfere in Iran’s domestic affairs,” he said. “They have to recognize our nuclear rights—put away bullying policies against Iran.”

Rouhani’s election stunned many Iran-watchers in the United States, who’d convinced themselves that Ayatollah Ali Khamenei, Iran’s supreme leader, had rigged the field so that Jalili or one of the other conservatives would win. In a June 12 editorial, The Washington Post huffed, “Rouhani, who has emerged as the default candidate of Iran’s reformists, will not be allowed to win.” But the 64-year-old cleric created a pre-election surge, reflected in several polls, by building a coalition of women, young people, liberals, reformists, business people and others who saw him as Iran’s best choice for change. He pledged to repair Iran’s struggling economy—suffering from US-led economic sanctions and catastrophic mismanagement under Ahmadinejad—and said he’d ease the oppressive crackdown by the morals police, favor women’s rights and end the militarization of Iran’s political life.

Still, Rouhani has a difficult road ahead. A decade ago, when President Khatami sought to make changes in the system, including an effort to lessen the power of the supreme leader, nearly all his reform plans—passed by a Parliament overwhelmingly dominated by reformists—were shot down by Khamenei and the Guardian Council. Now, Rouhani will have to maneuver intricately around Khamenei, a conservative-controlled Parliament and an ultraconservative judiciary—not to mention the fiefdom of the Islamic Revolutionary Guard Corps. Among the first changes that might come: allowing Iran’s media some breathing room, especially reformist newspapers and websites connected to the Green movement; rehabilitating moderate diplomats and technocrats purged during the Ahmadinejad era; and, perhaps most explosive, freeing political prisoners, including Mir Hussein Moussavi and Mehdi Karroubi, two Green candidates who ran against Ahmadinejad in 2009, both now under house arrest.

For President Obama, Rouhani’s victory presents a challenge and an opportunity. Though Obama, rather churlishly, didn’t congratulate Rouhani on his win, the president said, “I do think that there’s a possibility that they decide, the Iranians decide, to take us up on our offer to engage in a more serious, substantive way.” But there are plenty of things that Obama can do, even before Rouhani takes office, to bolster his struggle against the hardliners and to improve the chances that Iran and the United States can strike a deal.

First, the administration has to sweeten its offer to Iran, explicitly acknowledging its right to enrich uranium on its own soil in exchange for its agreement to accept more stringent UN inspections. And Obama—who, with Rouhani in power, will now have an easier time deflecting hawks, neoconservatives and the Israel lobby—must make it clear that economic sanctions will be lifted if an accord is struck. Rouhani, who has called for an end to sanctions, has already pledged to make Iran’s program more transparent.

And second, Obama must seek a deal with Iran over conflicts in Syria, Iraq and Afghanistan. Washington’s vow to give military aid to the rebels fighting the Syrian regime of Bashar al-Assad, Iran’s chief regional ally, will stir up Iranian hardliners, especially the Revolutionary Guards, and make Rouhani’s task far more complicated. In his post-election news conference, he gave a crucial sign that he might be ready for compromise over Syria by signaling that he wants better relations with Saudi Arabia, the chief backer of the rebels. For starters, Obama ought to explore that opening by inviting Iran to take part in the proposed Geneva peace conference.

Read Bob Dreyfuss's earlier coverage of the lead-up to the Iranian election here and here.