At the end of the day, one supreme reality kept the P5+1 negotiators in Vienna: the belief that the consequences of failure would be far worse than forging an imperfect deal on Iran's nuclear program. It was this basic assessment of the stark alternatives that led to the historic accord signed yesterday in the Austrian capital.

Of course, Secretary of State John Kerry did not (and could not) articulate this point directly. On the contrary, he warned that the U.S. was ready to walk away from the table. But his admonition was mostly meant for his U.S. critics, many of whom denounced the Vienna talks before the negotiators had sipped a single coffee or munched one Twizzlers stick.

As for the Iranians, they happily chimed in that they would not be the first ones to leave the negotiations, thus calling what they deemed to be an American bluff.

In this game of chicken, the Iranians probably calculated that if the talks collapsed the following might happen:

1.) Iran could selectively endorse those provisions of the April 2 "Framework Deal" that favored Tehran's interests, thus appearing cooperative despite the failed talks. 2.) The international coalition that had sustained sanctions would soon fray, removing any further impetus for Iran to compromise. 3.) Iran would then be well-positioned to pursue enrichment without suffering the intrusive inspections regime that would have been imposed by a negotiated agreement. 4.) The U.S. then would have to choose between a policy of containment and going to war with Iran. 5.) If the U.S. resorted to force, Iran's nuclear program would absorb a tremendous blow, but it would probably be rebuilt with the full support of the Iranian populace and sympathy from much of the international community.

Iran's leaders believed that a failed deal could be better for Tehran than for Washington.

This perception was hardly unreasonable. In the lengthy run up to the June 2015 talks, U.S. leaders repeatedly asserted that "sanctions brought Iran to the negotiating table." In point of fact, from the very start of the P5+1 talks, geo-strategic conditions in the region and beyond did not favor Washington. These conditions included the rising power of ISIS in Iraq and Syria, a development that Tehran believed enhanced its diplomatic leverage.

But the bigger and more fundamental strategic problem was two decades of incoherent U.S. Iran policy. Based in part on the unrealistic demand that Iran accept "zero enrichment" as the basis for any deal, this policy unwittingly abetted the expansion of Iran's nuclear program.

Indeed, by the time President Obama arrived at the White House, Washington had to wrestle with a much more inauspicious context: an Iran that had thousands more spinning centrifuges and an international community that was divided precisely because "zero enrichment" was a nonstarter for any serious negotiations. Dropping this policy surely helped to unite the international community behind a common negotiating position. But by 2012, Tehran also had far more room to "bargain down" its program, thus complicating the Obama administration's diplomatic task.

This does not mean that Washington lacked cards to play or that Iran had so many advantages that it could reject compromises that would greatly attenuate its nuclear program. The prospect of sanctions relief fed hopes in Iran's struggling middle class for better times. Having pinned their very political careers to these hopes, President Hassan Rouhani and his foreign minister were loathe to abandon talks that, if collapsed, could undermine their project of political and social reform at home.

Thus their calculation — which the Supreme Leader Ali Khamanei's surely shared — that accepting some difficult compromises on, for example, the timing of sanction relief, was smart diplomacy. These calculations kept the talks going, despite rising tensions between Iran and the U.S. during the hot days of late June.

These tensions apparently escalated after Tehran's last-minute assertion that a final deal should end the U.N. arms embargo on Iran. Given the progress that had been made on other hard issues, it is interesting that Iran chose to push the embargo issue in a manner that apparently shook the trust that had been carefully nurtured between Secretary Kerry and Foreign Minister Mohammad Javad Zarif.

Still, both men knew that because the arms embargo engages a far wider strategic issue than the nuclear question — namely the regional role that Iran will play after an agreement — it could not be directly or usefully litigated in Vienna. Thus they stepped back from the brink.

It may very well be that the U.S. had more to lose than Tehran from a collapse of the talks. But this fact alone does not diminish the importance of what was accomplished in Vienna. For both the U.S. and Iran, the risks of the accord are far outweighed by the potential benefits, particularly given alternatives that neither country could confidently or safely predict. For all concerned, failure was not an option.

Daniel Brumberg is a special adviser at the United States Institute of Peace. The views expressed are his own. Thinking of submitting an op-ed to the Washington Examiner? Be sure to read our guidelines on submissions.