If, as is now being reported, the U.S. and Iran are planning to work together to contain the Sunni insurgency in Iraq, the consequences for the Middle East and U.S. foreign policy are incalculable. Given the stakes involved in the sweep through Iraq being conducted by the radical Sunni Islamists, it is clear that the Obama administration must do more than wring its hands with the president once again playing Hamlet as an international crisis gets out of control. Iran is even more heavily invested in the survival of the Shiite majority government in Baghdad, so it is likely that it will be only too happy to coordinate with the U.S.–though the ayatollahs may be about to discover that Barack Obama is a much better person to have as an adversary than as an ally. But even if the U.S. proves to be too fearful of being drawn back into a war that the president has constantly boasted of having “ended” to be of much use in Iraq, the Iranians still have a lot to gain from cooperation on this front.

As our Michael Rubin observed earlier today, past efforts at U.S.-Iran coordination in Iraq did not exactly work to the benefit of the Americans—or the Iraqis. The example he cited of what happened when Iranian auxiliaries become entrenched—as was the case in Lebanon—is very much to the point. Any hopes that the free Iraq that thousands of Americans died to create—and which seemed well within reach when George W. Bush left the presidency after his victorious surge—can be salvaged seem utterly lost. But there is another, potentially bigger problem that stems from this decision to work with Tehran that is being forgotten amid the justified concerns about the collapse of Iraq: Iran’s nuclear program.

Though the Iranians don’t wish to see the Shiite-dominated government in Baghdad fall, this crisis couldn’t have come at a better time for them. After months of stonewalling the Obama administration’s efforts to craft another nuclear deal that would at least look like the West was doing something to stop Tehran’s weapons program, Iran’s leverage over Washington and its European allies has just increased exponentially.

There is plenty of blame to go around here. Critics of the U.S. invasion of Iraq are right when they point out that Iran was immeasurably strengthened by the fall of Saddam Hussein as well as by the diversion of attention from their terrorism and nuclear program. It must also be acknowledged that President Obama’s haste in fleeing from Iraq led directly to the successful revival of the Sunni insurgency.

The administration’s zeal for a deal that would end the confrontation over Iran’s nuclear ambitions has been no secret since it concluded an interim pact last November that tacitly recognized Iran’s “right” to enrich uranium and started the unraveling of the economic sanctions that had taken years to enact and enforce. The Iraqi crisis not only strengthens Tehran’s already strong bargaining position in the continuing P5+1 talks; it also gives President Obama one more reason to seek to appease Iran rather than pressure it to make concessions on outstanding issues such as its ballistic missile program or its nuclear military research.

Earlier this year the president demonstrated that he could sell even an embarrassingly weak deal with Iran to the country by branding its critics as warmongers when they tried unsuccessfully to get Congress to pass new sanctions legislation. But if he can claim that Iran is helping out in Iraq, it will be that much easier for him to stifle criticism of the next nuclear pact even if all it does is to make it a little bit harder for Tehran to “break out” and obtain a weapon after the deal is signed. Even worse, it may provide an excuse for the administration to backtrack from his 2012 promise that he would never countenance a policy of “containment” of a nuclear Iran. Since Iran’s conduct in Iraq will be portrayed as evidence of its rationality and willingness to be part of the international community, its potential to create a nuclear arsenal will likely also be dismissed as regrettable but no great threat to U.S. security.

But any such assumption would be a tragic mistake.

If Washington were to make the leap from irresolute diplomacy to a policy shift that treated the nuclear issue as a sidebar to the more important question of Iraq, the result would make an already unstable Middle East even more dangerous for the U.S. and its allies. While the prospect of letting either parts or the entirety of Iraq fall into the hands of al-Qaeda-allied Islamists is a grim one, American acceptance of Iran’s nuclear dreams would be an even greater calamity. As President Obama has already repeatedly stated, Iranian nuclear weapons would be “a game changer” that would plunge the region into further conflict and instability even if the “rational” rulers of Tehran never used one. Iran’s network of state-sponsored international terrorists would gain a nuclear umbrella. Moderate Arab states would, at best, be endangered and would look to obtain their own nuclear option. The already remote chances of Middle East peace would be finished.

The president’s defenders may claim that he is capable of working with the ayatollahs in Iraq without abandoning his pledges never to accept an Iranian nuke. There is also no question that the administration must act expeditiously in Iraq and some coordination or at least communication about the struggle with Iran is necessary. But given that the entire thrust of U.S. diplomacy in the last year has been focused not so much on a nuclear compromise as on an effort to foster a new détente with the Islamist regime, it is difficult to imagine how the events of the last week will do anything but diminish his already flagging determination to stop Iran.