TEHRAN, Iran – For Iranian President Hassan Rouhani, winning re-election may have been the easy part.
His wide-margin victory over a hard-line rival shows a majority of Iranian voters prefer his promises of greater liberalization at home and deeper engagement with the world.
It is a win that brings hope to Iran's reform-minded urbanites and bulging youth population, who long to see their country move past its image as an oppressive and insular nation cut off from the West. That was clear from the throngs of chanting, clapping and dancing supporters who poured into Tehran's streets to celebrate his victory.
"I hope we can enjoy more freedom and security in the next four years," said one, Ramin Mirzai, a 21-year-old Tehran University student.
"I expect Rouhani to lift the house arrest" of opposition leaders, said another, drafting technician Farnoosh Kazemi, 26. "Work with neighboring and other international countries to make a better atmosphere in the country. We need more investment."
Meeting those expectations will be no simple task.
Among his toughest challenges will be to turn around the OPEC producer's sputtering economy.
Hard-line critics in parliament and elsewhere berated his administration as it worked to secure the 2015 nuclear deal with world powers, which saw Iran accept curbs on its contested nuclear program in exchange for sanctions relief. They argued it gave away too much for too little.
The economy has improved since the deal took effect last year. But to many ordinary Iranians, the hard-liners' argument rings true.
Although Rouhani scored some wins in the deal, including multibillion-dollar commercial aircraft agreements, the economy remains hobbled by excessive state control, a prolonged slump in global oil prices and extensive non-nuclear sanctions still in place. Unemployment is in the double-digits. Nearly a third of young people are out of work.
Foreign banks, wary of running afoul of continuing sanctions, remain wary of processing financial transactions involving Iran, let alone lending to or investing in Iranian companies.
"It's a kind of conditional lifting of sanctions," complained Shahabedin Yasemi, an executive at Tehran-based mining company Sabanour. "If borders were open, foreign investors would dare to come and start something here."
Rouhani also pushed boundaries during the campaign by taking unusually pointed swipes at hard-liners within the Iranian establishment.
During one presidential debate, he criticized the launch of a ballistic missile bearing the words "Israel must be wiped out" in Hebrew — an implicit critique of the Revolutionary Guard that controls the missile program.
It is a delicate path. Since the 1979 Islamic Revolution, the Guard has grown into an immensely powerful force with its own navy and foreign operations arm. It controls key domestic sites including the country's airports.
The Guard also runs a vast, intertwined network of lucrative businesses that could suffer from economic reforms aimed at improving the economy.
That kind of power enables the Guard to sabotage a sitting president's agenda with embarrassing displays like the missile launch or harassing U.S. Navy ships transiting the Persian Gulf.
It's not letting up either. The Guard just this week boasted that it opened a third underground ballistic missile production site, mocking the threat of sanctions by saying it has no concern about "U.S. businessmen's fears."
Rouhani, no doubt mindful of the Guard's power, made a point of flattering the force and other conservative power centers such as the Basij volunteer militia during his first postelection news conference.
"The people say no to the downfall of the supreme leader, Guard, Basij and armed forces, because they belong to the entire Iranian nation," he said.
He also took care not to strain ties with another bastion of hard-line power: the country's judiciary. As with the Guard, Iran's president has no direct control over the courts.
That powerlessness is made clear whenever the jailing of Iranian dual nationals ratchets up tension with the West, like the 2014 detention of Iranian-American reporter Jason Rezaian. Rouhani's foreign minister, Mohammed Javad Zarif, at the time called the Washington Post journalist a fair reporter while expressing hope the case could be resolved.
Rezaian nonetheless ended up being tried by one of Iran's toughest judges and convicted of charges including espionage in a closed-door trial. He was eventually released in a prisoner swap with the U.S.
The judiciary's influence could also make it hard for Rouhani to see through another of his supporters' goals: securing the release of Green Movement opposition leaders confined to house arrest following Iran's disputed 2009 presidential election.
Rouhani's supporters frequently broke out in chants supporting detained reformist Mir Hossein Mousavi at recent rallies supporting the president.
Rouhani made clear after the election he remains concerned about the detentions. But he also acknowledged his limits, saying that the executive, legislative and judicial branches of government each "have to work within their frameworks."
Sitting above everything is Supreme Leader Ayatollah Ali Khamenei, arguably the biggest check on Rouhani. Khamenei has the final say on all state matters. He is not known for his embrace of major reform.
"Khamenei and conservatives in his office still run the show, are close to vested interests, and will make structural change difficult," Iran watcher Cliff Kupchan, chairman of the Eurasia Group, wrote shortly after Rouhani's win.
So too could U.S. President Donald Trump's renewed push to isolate Iran — a policy likely to embolden hard-liners.
Rouhani seems well aware of that threat. During his news conference this week, he leavened talk of international outreach "based on mutual respect ... and mutual interests" with some biting barbs aimed at the U.S. — perhaps to outdo the hard-liners themselves.
"The U.S. leaders should know that whenever we need missile tests ... we will test. We will not wait for them and their permission," he said.
As for the Trump administration? He said he was "waiting for this government to become stable intellectually" before making a judgment.
Associated Press writer Nasser Karimi contributed.
Schreck is a regional news director for The Associated Press, overseeing coverage of Iran and six Gulf Arab countries. He covered the 2017 Iranian presidential election from Tehran. Follow him on Twitter at www.twitter.com/adamschreck.