Barack Obama came into office in 2009 having campaigned on a more realistic policy in the Middle East, including toward Iran, after George W. Bush’s crusades. Obama’s determination to reach out to Iran has finally borne fruit. Whereas some of his other Middle East policies met setbacks or suffered policy drift, in the Vienna agreement he and Secretary of State John Kerry achieved through diplomacy a reconfiguration of the Middle East as consequential as George W. Bush’s overthrow of the Saddam Hussein regime in Iraq. Obama did it through diplomacy rather than war, however, making his legacy a long-term and positive one for the region.

The agreement reached this week is a milestone in the campaign against nuclear proliferation. It attempts to close off possible technical pathways for Iran to create a nuclear weapon (something the ayatollahs have in any case steadfastly denied they wish to do). At the same time, it permits Iran the use of civilian nuclear energy for the purposes of electricity generation, a program important to the country so as to preserve its natural gas and petroleum for export and to build up its foreign currency reserves, rather than squandering these resources at home. Peaceful nuclear reactors are a guaranteed right to countries under the Nuclear Non-Proliferation Treaty, a right on which Iran has insisted.

Critics of the plan who discount the efficacy of inspections should remember that no country under formal International Atomic Energy Agency inspections has ever developed a nuclear weapon. Those skeptics who insisted that UN inspections of Iraq in the 1990s had failed were surprised in 2003 to discover that, in fact, they had completely closed down Saddam Hussein’s small and not very advanced nuclear labs, which he had authorized in an arms race with nuclear-armed Israel. The only alternative to a negotiated settlement of this sort, in any case, would have been a war on Iran that would have been costly and perhaps ruinous (the country is three times bigger and more than twice as populous as Iraq, and it is not as if the US economy has emerged unscathed from the latter misadventure).

President Obama first signaled his new approach to Iran in his Persian New Year’s (Now-Ruz) message in March of 2009. He called the country the Islamic Republic of Iran and declined to make a distinction between the Iranian people and their government. The Iranian leader Ayatollah Ali Khamenei was clearly intrigued by this initiative, but said (to translate into our idiom) the proof will be in the pudding.

The United States has a long history of aggressive intervention in Iran, mainly having to do with petroleum. It helped depose the Iranian government in 1941 and jointly occupied the country with Britain and Russia during World War II, during which it presided over a collapse of the economy and a horrible famine. It made a CIA coup in 1953 to crush a democratic movement seeking a better deal from the British on Iranian petroleum, and installed Shah Mohammad Reza Pahlevi as a pro-American dictator. In the 1960s, whenever the Shah’s oil prices seemed excessive to Washington, officials were sent out casually to threaten him with another coup unless he fell back in line. Outraged at the Shah’s increasingly onerous, seedy police state, the Iranian people made a revolution against it in 1979, blaming the United States for decades of repression, jailings, and torture of regime critics.

When Saddam Hussein’s Iraq launched a war of naked aggression on Iran in 1980, seeking to seize its southwestern oil fields, the United States gradually swung around to allying with Baghdad, the aggressor. In the mid–1980s, the Reagan administration deflected Iran’s attempt to bring Saddam Hussein up on charges before the UN Security Council of using chemical weapons like mustard gas at the front. When Israel launched a war of aggression on little Lebanon in 1982 and occupied the southern, largely Shiite-populated region of that country, the United States was complaisant. Iran, in contrast, helped organize Lebanese Shiites for a long resistance to occupation. The United States castigated that resistance as “terrorism.” After 2003, powerful Washington officials such as Dick Cheney repeatedly threatened to attack Iran from occupied Iraq. From Tehran’s point-of-view, if you could think of a nasty thing that could be done to Iran and its people in the past seven decades, the United States has done it. Hence Khamenei’s caution about Obama’s suddenly outstretched hand.

All this is not to excuse Iran’s leadership for its own faults after the 1979 revolution. The taking of US hostages at the American Embassy in Tehran in November of that year will forever be a blot on the country’s rule-of-law. Ayatollah Ruhollah Khomeini conceived of himself as leading a global Muslim struggle against the United States on the basis of theocracy and clerical rule. His allies blew up the US Embassy in Beirut. He declared the Muslim world’s monarchies illegitimate in Islamic law, saying that there was no place for kings in Islam, causing alarm from Rabat to Riyadh. He called on the Shiites of Iraq to rise up against their government, helping provoke Saddam’s military response. Going beyond agitating for rights for the stateless Palestinians, he set himself against Israel’s legitimacy (though the current Iranian government has a “no first strike” policy and has not threatened Israel with military invasion, contrary to what is frequently alleged). Inside Iran, Khomeini dismantled the democratic institutions that revolutionaries tried to set up in 1979 and ultimately approved the killing of thousands of dissidents. Revolutionary Iran was not a country but a cause, and its leaders did not care how much instability and destruction they caused to achieve their goals.

When Obama came into office in 2009, he inherited this troubled history of imperialism and radicalism, but judged that changing world conditions had made possible a new relationship with Iran. The Bush administration had simply refused to talk to regimes it did not like, such as Cuba or Iran, which Obama felt was foolish, and felt did not actually punish those regimes. Obama’s main obstacle to opening Iran was by then that government’s nuclear enrichment program, begun in the late 1990s. Contemporary enrichment technology using centrifuges is unfortunately always potentially dual-use. If the uranium is spun around with radioactive gas in the centrifuges a little bit, it is enriched to 3 to 5 percent, becoming suitable as fuel for nuclear reactors. If it is enriched to 19.5 percent, it can fuel medical reactors for creating isotopes to fight cancer. But if it is enriched to 95 percent, it can be used to make a bomb, assuming the government involved has other technical abilities and equipment.

Nuclear-armed states, i.e. Israel, the United States, France, Britain, Russia, China, North Korea, India, and Pakistan, see their weapons as defensive. They are determined that no more countries should join their select club, and the rise of centrifuge enrichment technology has therefore created security anxieties for them, since on the one hand it is difficult to deny countries centrifuges, but on the other, they could be misused if a government decided to go in that direction. The UN Security Council, suspicious of Iran’s motives, more or less unilaterally ordered it to give up enrichment and centrifuges entirely in the mid–2000s (despite the NPT’s guarantee of a right to this technology to countries that use it for peaceful purposes).

Since Tehran defied the UNSC, continuing to enrich but denying it was doing so for military purposes, the UNSC member states placed economic sanctions on Iran. Since about 2012, the United States has more or less imposed a financial blockade on Iran, interfering with its oil sales around the world and forbidding international banks to allow transactions with Tehran. The sanctions have hurt, though they did not destroy, Iran’s oil industry, reducing exports from 2.5 million barrels a day to 1.5 million (China paid no attention to US arm-twisting and continued to import Iranian oil; India had little choice but to do so as well). Some of the damage was offset by increased Iranian non-oil exports, since its currency softened because of the sanctions and the financial blockade.

The pain was sufficient, however, to convince hard-liners such as Khamenei to give President Hassan Rouhani (elected in 2013) and his foreign minister Javad Zarif permission to see if negotiations could end the sanctions without injuring Iranian sovereignty. Inside Iran, Khamenei had had his hands burned by the right-wing populists of former president Mahmoud Ahmadinejad and was searching for a new coalition of centrists and pragmatic hard-liners. Obama finally had negotiating partners on the Iranian side he could work with and who could deliver, unlike the Ahmadinejad team his officials met with at Geneva in the fall of 2009, who were (literally) slapped down by the leader and the hard-liners when they were accused of giving away too much to the United States.

As an expert in Shiite Islam and Iran, I have long argued that Khamenei is sincere about not wanting a nuclear weapon. He has repeatedly given oral fatwas or legal rulings that stockpiling and using such weapons is contrary to Islamic law, which forbids such indiscriminate killing of noncombatants. For Westerners to hold that he nevertheless wants a nuke is a little like maintaining that the Vatican has a condom factory in its basement. Perhaps some generals in the Iranian Revolutionary Guard Corps do want a bomb. The compromise the regime has settled upon, in my view, is nuclear latency or a breakout option. That is, they have developed all the infrastructure and technical knowledge and equipment that would be necessary to make a nuclear weapon, but stop there, much the way Japan has.

A breakout option has some of the same deterrent effect as possessing an actual bomb (an aggressive enemy can never know whether its intended victim might be close enough to a warhead to fight back with lethal force if pressed). But it does not attract the kind of isolation and world opprobrium that has been visited on North Korea since it openly went for a bomb. Precisely because a breakout option has deterrent effects, regional hegemons such as Israel and Saudi Arabia are alarmed by Iran’s new capability. It is not because they think Iran will make a bomb (nuclear weapons have since 1946 had only a defensive capacity in any case, because of Mutual Assured Destruction among nuclear states). It is because they know the regime cannot any longer be attacked and overthrown, and that the long counterrevolution against Iran they have pursued is over.

The Obama administration and its colleagues, the permanent members of the UN Security Council plus Germany, determined that to deny Iran enrichment capabilities for energy purposes entirely was unrealistic. The question, then, was how to allow enrichment but forestall any attempt at militarization. The comprehensive inspection regime that has been agreed to at Vienna was their solution to this problem. It is an imperfect solution, but the best one available short of war and occupation.

Any diplomatic agreement is only as good as its implementation. Because it is complex and because it is hated by Tel Aviv, Riyadh, and most state capitals of the American South, the deal still faces some rough waters. Congress, persuaded by the Israel and Gulf Arab lobbies, could shoot it down. Hard-liners in Tehran could find some way to back out. But another outcome is possible, which might be called the Vietnamese solution. No more than the United States and Vietnam can Washington and Tehran expect abruptly to put behind them decades of disagreement (that is why critiques that the deal did not go beyond resolving the nuclear conflict are silly). But the United States does have diplomatic relations with Vietnam, and as of this year the two now cooperate on policy goals in the Pacific Rim. That is because the United States has abandoned its anti-Communist crusade and Vietnam has given up the goal of fostering regional revolution.

Intransigent causes are deadly to world peace. As recently as the Bush administration in the United States and the Ahmadinejad government in Iran, both countries were still acting as though they were a cause. If the United States and Iran can begin behaving like responsible governments instead, they have a rare opportunity to transcend a particularly nasty history with one another. One piece of good news: Much of the animosity between the two countries was driven by competition for control of valuable hydrocarbons, which the world is likely to (and must) give up over the next two decades.