President Donald Trump is having, even by his standards, a very bad week. On Monday alone, quite apart from the continuing Russia scandal, he found himself blocked from fulfilling his dreams and campaign promises to repeal the two landmark achievements of the Obama years—the Affordable Care Act and the Iran nuclear deal.

In the former, Senate Republican leaders couldn’t muster enough votes, even within their own party, for an alternative plan that was drawn up in secret and would snatch health care from more than 20 million Americans. In the latter, Trump was met with—and, at first, tried to resist—an unpleasant surprise: The Iranians, it turns out, are in full compliance with the accord’s quite stringent terms. The deal, which Trump and other critics had denounced as dangerous and unworkable, is working.

Shortly after the deal was signed in July 2015 by Iran and six other nations (the five permanent members of the U.N. Security Council—the United States, Britain, France, Russia, China—plus Germany), the U.S. Congress passed a bill requiring the president to report every 90 days on whether Iran was keeping its end of the bargain. Monday was the most recent 90-day deadline.

Want to listen to this article out loud? Hear it on Slate Voice.

In June, as the deadline approached, the White House was dealt a crushing blow by the International Atomic Energy Agency, which has been monitoring the deal under the most intrusive inspection regime ever negotiated in an arms-control accord. The IAEA concluded—in its own detailed, point-by-point report on the matter—that the Iranians have so far followed the accord to the letter.

The deal required Iran to reduce the number of centrifuges in its reactors by two-thirds; to reduce its stockpile of enriched uranium by 97 percent; to destroy the core of a heavy-water reactor that might have produced plutonium bombs; and to allow IAEA inspectors to enter, monitor, and take measurements not only at “known” nuclear facilities but also at “suspect” covert sites. The agency’s findings of Iran’s compliance with these and other requirements: check, check, check, and check.

At an hourlong meeting on Wednesday, Trump’s top security advisers—Secretary of State Rex Tillerson; Secretary of Defense James Mattis; Lt. Gen. H.R. McMaster, the national security adviser; and Gen. Joseph Dunford, the chairman of the Joint Chiefs of Staff—unanimously told the president he had no choice but to certify that Iran was in compliance. But, according to a story by Peter Baker in the New York Times, Trump spent 55 minutes of the meeting telling his advisers “he did not want to.”

Over the next several days, the advisers crafted what they presented to Trump as a tough new policy: He would sign the certification but also stiffen U.S. sanctions against Iran for its development of ballistic missiles, support of terrorism, and violation of human rights.

In fact, though, the advisers were craftier than Trump knew. Under the nuclear deal, the U.S. and the five other signatories agreed to lift sanctions that they had imposed on Iran for its nuclear activities, which had previously been in violation of United Nations resolutions. However, the deal explicitly stated that the sanctions that had been imposed on Iran for other nefarious activities could stay in place. In other words, the advisers’ proposal, which Trump accepted, was no new policy, not even much of a shift. It is allowed for in the nuclear deal—and the United States, along with other countries, have been imposing sanctions on Iran, under those other criteria, for years.

McMaster seemed to keep up the rhetorical ploy on Monday in a conference call with reporters, telling them that Iran had breached “the spirit” of the nuclear deal and “has been walking up to violating the letter” of it as well. Like many American soldiers who fought in Iraq, McMaster is deeply suspicious of Iran, but he has also read the agreement’s text, so his words here can only be seen as disingenuous. For the text was composed so precisely that there is no distinction between its “spirit” and its “letter”; the only way of violating the former is to violate the latter.

So, yes, Iran continues to do things that we don’t like, but those things—testing missiles, financing terrorists, oppressing internal critics, expanding its influence across the Middle East—were not covered by the accord, and deliberately so. Iran’s impending nuclear threat was seen as the urgent danger; wrapping talks over that threat into some “grand bargain,” which would settle all of our differences, was seen as a fool’s errand and a distracting delay. Analogies were drawn to the U.S.-Soviet nuclear arms-reduction treaties signed during the Cold War. Those treaties said nothing about Moscow’s communist ideology, its oppression of dissidents, its occupation of Eastern Europe, or its support for developing countries’ revolutionary movements. But the treaties were valuable nonetheless for staving off the danger of nuclear war.

It’s true that Obama and some of his aides hoped that the nuclear deal with Iran might alter Tehran’s policies over time—in part by drawing the country into the global economy after decades of isolation, in part by strengthening the domestic leverage of President Hassan Rouhani and Foreign Minister Mohammad Javad Zarif, who had initiated the overture to the West and are thought to be more Western-leaning than the mullahs who presently rule Iran’s politics.

However, Obama also said, publicly and privately, that the deal was a good deal—for the security of the United States and its allies, including those in the Middle East—whether or not Iran changed its broader outlook. Which would be worse, Obama would ask: an aggressive Iran with nuclear weapons or an aggressive Iran without nuclear weapons? To critics who complained that the deal prevented Iran from going nuclear for just 10 years (though actually it blocked some critical paths to a bomb for 15 and 25 years), Obama would ask: Would you rather leave Iran with the ability to build a bomb in one year, which it possessed when the deal was signed?

“They might cheat” remained the critics’ only substantive line of attack. And even Trump has been forced to admit that, at least for now, they’re not cheating. There is no “spirit” of the deal that the Iranians are violating. And as for McMaster’s claim that they’re “walking up to violating the letter” of the deal, that’s just another way of saying that they’re not violating its letter. They may be doing everything up to the limits of what the deal allows—but, again, those limits fall far short of what Iran needs to get remotely close to acquiring a nuclear weapon.

Meanwhile, if Trump is worried about Iranian expansion (a legitimate source of worry), he seems oblivious to the fact that his own policies have worsened the trends. By denouncing Qatar as a leading financier of terrorism (thus succumbing to sweet-talking pressure from the Saudis and an info-war hacking campaign by the UAE), Trump drove Qatar’s emir—who, yes, had been playing all sides in the sectarian wars but had also been hosting the largest U.S. air base in the Middle East—into the arms of … that’s right, Iran. By aiding the Saudis in their vicious air war over Yemen and killing many more civilians than Obama had in his own abetting, Trump has helped legitimize Iran’s support of the rebels. By failing even to attempt a politico-diplomatic settlement to the civil wars in Iraq and Syria (even as the military campaigns against ISIS are succeeding), he has solidified Iran’s political control of Baghdad. (In fairness, though, Iran’s growing influence in Iraq was an almost an almost inevitable consequence of the power vacuum left by President George W. Bush’s 2003 invasion.)

Trump also made a terrible mistake when, during the NATO summit in May, he tried to persuade European allies to stop their trade and financial transactions with Iran. By doing this, the United States accomplished the dubious feat of being the first power to violate the Iran nuclear deal. For instance, in the accord, the United States and European Union pledge to “refrain from any policy specifically intended to directly and adversely affect the normalization of trade and economic relations with Iran inconsistent with their commitments not to undermine the successful implementation of this [agreement].” They also agreed on “steps to ensure Iran’s access in areas of trade, technology, finance and energy.”

Zarif, Iran’s foreign minister who is visiting New York, argued explicitly on Monday, at a meeting of the Council on Foreign Relations, that Trump has violated the nuclear deal. The multinational commission that periodically reviews compliance with the deal is meeting in Vienna this Thursday. It shouldn’t be a surprise if Iran’s delegates use the occasion to file a formal complaint against the United States.

The complaint isn’t likely to amount to much. Trump’s lobbying in Europe had no effect. Western firms have begun to sign contracts in areas of commerce the nuclear deal allows, and American firms would be loath to grant foreign competitors a leg up to appease Trump’s pique.

It is a devastating sign—not only of how poorly Trump understands foreign policy but also of how inadequately his vaunted deal-making skills translate to international politics—that an American president is being outflanked so easily by an Iranian foreign minister. It’s a sorrier sign still that the Iranian foreign minister is in the right.