A professional conflict mediator, who had helped manage peace talks on three continents, once told me that the key to winning an agreement was to look past what each side was demanding and focus instead on the core needs and desires motivating those demands.

We recognize this when we fight with our spouses: an argument over who walks the dogs might actually be driven by something deeper, and so it's neither sufficient nor sometimes even necessary to change the dog-walking schedule in order to fix it. This is true of countries as well, the mediator told me, and often more so because the surface issues can be so complex and difficult on their own that it's easy to miss the underlying motivations that brought both sides into conflict in the first place.

This realization, based on the details that are now emerging from the final grueling week of negotiations with Iran over its nuclear program, appears to have been a core breakthrough that allowed last week's framework to go from a seeming impossibility to a reality.

"Iran was willing to waste 1,000 centrifuges, essentially spinning uselessly, to preserve national pride"

Part of what has made a deal so difficult is that on the surface, it's all about an issue that would seem zero-sum: how much of a nuclear program is Iran allowed to have? When you look at it this way, then every centrifuge Iran gives up is painful for the Iranians; every centrifuge Iran keeps is painful for the Americans. There's no way forward.

At some point, it seems, negotiators stopped looking at it that way, and started asking what was really important for both side. For the Americans, it was keeping Iran from being able to build a nuclear bomb. For the Iranians, it was a sense of national pride and sovereignty.

Both of those are linked closely to the size of Iran's nuclear program, but there are ways to address the American concerns by doing things other than cutting back the size of Iran's nuclear program. And there are ways to address the Iranian needs by doing things other than letting it keep a bunch of its nuclear program. Even though many of their terms were mutually exclusive, it turned out that their underlying goals were not. And the two sides, it seems, could not come to understand that until after they spent countless hours locked in the same rooms.

When you look at the framework terms, you can see how Iranians and Americans separated those issues out and found resolutions where none seemed possible. Take, for example, the Iranian nuclear facility known as Fordow, a hardened bunker built to withstand military bombings. The Americans wanted it closed because they saw it as designed to develop a nuclear bomb; the Iranians wanted it open as a symbol of their resolve and strength against outside powers. The disagreement seemed irresolvable.

But they did find a solution: Fordow would stay open, and would be allowed to include 1,000 working centrifuges, allowing Iran to declare victory in keeping it running. But the facility would be under invasive international inspections, and the centrifuges wouldn't be allowed to use fissile material but only medical isotopes useless for building a weapon, thus satisfying American demands.

"Administration officials were struck by the fact that Iran was willing to waste 1,000 centrifuges, essentially spinning uselessly, to preserve national pride," the New York Times's David Sanger and Michael Gordon wrote. The restrictions were so severe that US Energy Secretary Ernest Moniz could personally assure President Obama that Fordow posed no threat.

Another telling example is what they did about the reactor at Arak, which can be used to produce plutonium, one of two fuels for a nuclear bomb (the other is uranium). The Americans wanted it shut down as a threatening tool with which Iran could develop a bomb; the Iranians saw shutting it down as an intolerable national humiliation, and keeping it open as necessary to preserve the country's sense of strength and scientific achievement.

The solution they found is for Iran to dismantle Arak's core and replace it with a new core that will only produce benign power-plant fuel, along with other restrictions. As with Fordow, Moniz looked at the terms and determined that Arak would no longer be useful for developing a weapon, and that if the Iranians tried to cheat it would be immediately detectable. As with Fordow, the Iranians got their core demand satisfied, as well.

When Iranian Foreign Minister Javad Zarif announced these terms, then, he was able to frame them as a series of Iranian victories. "We will continue enriching, we will continue research and development, our heavy-water reactor [at Arak] will be modernized, and our facility in Fordow will remain open," he said.

Everything Zarif said was true, and accurately reflected the terms of the framework. But it was done in a way that also allowed the Americans to honestly say the deal will vastly restrict Iran's ability to take steps toward a nuclear bomb. It wasn't that both sides were spinning the terms to look more favorable than they were; the terms of Fordow and Arak are in fact mutually favorable to both sides.

But there is a real danger here: Javad Zarif and his negotiators do not make the final decision for Iran. That is up to Iranian Supreme Leader Ayatollah Ali Khamenei. If it turns out that the Iranian negotiators misunderstood Khamenei's bottom line, if they misjudged his underlying motivations, then it will have all been for nothing.

Zarif, just like the Americans, is banking on the judgment that Khamenei's core objective is to preserve this sense of national pride and sovereignty. If they're right, then the terms they negotiate will likely be agreeable to Khamenei. If they're wrong and the supreme leader is actually after something else — maybe, for example, he fears a possible American invasion and wants to preserve the capability to quickly break out to a nuclear bomb — then Khamenei will almost certainly spike the deal as intolerable.

And there are still ways that the Iranian and American goals remain mutually exclusive, even now that the twos sides better understand one another. That is particularly true with an issue that has long been and seemingly remains the hardest: how and when to lift economic sanctions off of Iran.

Iran wants the sanctions to come off right away, both to give their economy a chance to recover and because, for the Iranians, keeping punitive sanctions in place for years to come smacks of mistreatment and perceived Western condescension. But the Americans rightly fear that lifting sanctions right away will leave Iran with less incentive to adhere to its end of the bargain.

It is very difficult to imagine any possible resolution to this that, as with Fordow and Arak, will satisfy both sides' underlying objectives. Unless there is a brilliant idea somewhere that can make everyone happy, someone will probably just have to suffer a painful defeat on this issue. If they don't, then the deal will almost certainly collapse.