DUBAI — Iran and the West could not have agreed a nuclear deal this week without the backing of Supreme Leader Ayatollah Ali Khamenei, who set aside his deep mistrust of the United States to end decades of Iranian isolation.
Iran and world powers reached a deal on Tuesday on curbing Iran's nuclear program for at least a decade in exchange for sanctions relief, bringing an end to 12 years of brinkmanship, threats and confrontation on the issue.
President Hassan Rouhani, a pragmatist elected in 2013, led the efforts to normalize relations with the outside world alongside Foreign Minister Mohammad Javad Zarif.
But Khamenei is the ultimate power in the Islamic Republic, and the 75-year-old cleric gave Rouhani crucial political cover to pursue long and arduous talks against the interests of powerful domestic opponents.
He appeared to embrace the process only cautiously and intervened frequently, laying out "red lines" in public speeches that appeared to commit negotiators to tough stances on some of the stickiest issues.
Late last month, as the talks entered their final phase, he said Iran would not allow inspectors to interview its nuclear scientists, and demanded sanctions be lifted as soon as a deal was reached, positions clearly unacceptable to Western powers.
But in the end, he allowed Iran's negotiators to strike a deal that allows inspectors extensive access to Iran's nuclear facilities.
"Khamenei left the door to a compromise open ... The entire exercise of drawing red lines was aimed at signaling to the great powers that Iran was not in a position of weakness," said Ali Vaez, senior Iran analyst at the International Crisis Group, said.
Throughout the process, Khamenei insisted that Iran did not need a deal and would not make humiliating concessions to the United States, which he often refers to as the "Great Satan."
And he expressed distrust of Washington's motives, suggesting that it had fabricated a reported military dimension to Iran's nuclear program as a means to vilify the Islamic Republic.
"They created the myth of nuclear weapons so they could say the Islamic Republic is a source of threat. No, the source of threat is America itself, with its unrestrained, destabilizing interventions," Khamenei said in April.
The message to hardliners was clear: Iran is negotiating with its eyes open and would only accept a deal that is in its interests.
Khamenei became supreme leader in 1989 after the death of Ayatollah Ruhollah Khomeini, who led the revolution to overthrow the pro-Western Shah. Despite lacking Khomeini's revolutionary authority and charisma, Khamenei has held on to power for 25 years by deftly balancing the interests of numerous factions.
In allowing a deal with Iran's enemies, he is taking a step similar to his predecessor's agreement to a 1988 cease-fire with Iraq after an eight-year war, which Khomeini compared at the time to drinking a cup of poison.
Iran has suffered under economic sanctions for decades, especially over the last three years, when much tighter U.S. and EU measures sharply curtailed the oil exports that are the foundation of its economy.
In 2009, the largest opposition demonstrations since the 1979 Islamic Revolution filled the streets. While that uprising was swiftly put down, it rattled the political establishment.
Four years later, they found in Rouhani a pragmatic presidential candidate whose promises to improve the struggling economy through international engagement were likely appeal to many of those who had taken to the streets.
Diplomats suggest that Rouhani's landslide win, as well as public anger over years of economic mismanagement, exacerbated by sanctions, under Rouhani's predecessor Mahmoud Ahmadinejad convinced Khamenei and other leading conservatives to back the relaunch of nuclear talks.
Scholars outside Iran describe the supreme leader as a secretive ideologue fearful of betrayal, an anxiety fueled by an assassination attempt in June 1981 that paralyzed his right arm.
He became close to the military, in particularly the elite Revolutionary Guards — a relationship that paid off when the Guards crushed the 2009 protests