Until recently the United States viewed the Islamic State in Iraq and Syria, or ISIS, as a major threat to regional stability in the Middle East. Barack Obama made it a mission to roll back ISIS’s territorial and propagandistic gain, and Donald Trump campaigned on a promise to “kick ISIS’s ass.” The United States expended considerable effort, both military and political, in a campaign to defeat the terror group in Iraq and, to a lesser extent, Syria.

But there is also no doubt that the bulk of the effort came from Iran, not the United States. Without Iranian involvement, ISIS would still have a formidable presence in both Iraq and Syria.

ISIS was born out of the ashes of the American invasion of Iraq. Their rise was the logical extension of a process that saw the fabric of secular Sunni society torn asunder by an American occupier unwilling to further empower a Sunni ruling elite that had been loyal to Saddam Hussein. Washington failed to understand the resentment engendered within the Sunni community when Iraq’s Shia, some of whom were beholden to Iran, came to power.

Traditional Sunni tribal power structures were eviscerated as a result, only to be replaced with radicalized Sunni youths beholden to only themselves. Al-Qaeda in Iraq (AQI) was al-Qaeda in name only—its mission wasn’t to export jihad to the West, but to free Iraq from the grips of an American and Iranian occupation.

America’s campaign against AQI never resulted in that movement’s destruction. Instead, the United States, in an effort to free itself of the burden of war created when it invaded Iraq in the first place, withdrew from Iraq in 2012, leaving the final phase of AQI’s destruction in the hands of the Iraqi government. This period coincided with the start of the civil unrest in Syria and the creation of a radicalized Islamist opposition to Syria’s president, Bashar al-Assad. The willingness to cede large swaths of Syrian territory to Islamist forces as a means of destabilizing Assad created the conditions for the birth of ISIS in the deserts of both central Syria and western Iraq.

When ISIS advanced on the Iraqi cities of Ramadi and Fallujah, the American-trained and -equipped Iraqi army was unable to halt its advance. Soon the major city of Mosul fell to ISIS, and its forces pushed down the Tigris River valley to the outskirts of Baghdad.

The story of Iraq’s struggle to form a viable resistance to ISIS in the aftermath of the fall of Mosul is little known, and even less appreciated, by the United States. The formation of so-called “Popular Mobilization Forces,” or PMF—organized at the behest of Iraq’s senior Shia leadership, and trained, equipped, and led by Iran—was the single most important factor behind the halting of ISIS’s drive on Baghdad and its eventual eviction from Iraqi territory.

Western media have paid a disproportionate amount of attention to the actions of a select few American-trained Iraqi security forces, which, with ample support from U.S. airpower and advisors, helped end fighting in and around Mosul. All the while, they’ve ignored that the lion’s share of the fighting was done by the Iranian-directed PMF. This fact was not lost on the Iraqi people, many of whom (though not many of the Sunnis) hold the PMF in the highest regard. This sentiment has propelled many of the senior leadership of the PMF into political prominence in Baghdad.

For Iran, the ISIS phenomenon is not limited to Iraq. It is seen as part and parcel of a concerted effort undertaken by the United States, Saudi Arabia, and the Gulf Arab nations to overthrow Assad in Syria, diminish the power and influence of Hezbollah in Lebanon, and roll back Iranian influence in both Syria and Iraq. ISIS’s geographic presence in Syria, concentrated as it was in the central and northeastern deserts, made it a secondary target compared to the al-Qaeda affiliates operating in and around Aleppo and Damascus.

As the Syrian government, with the assistance of Russia, Iran, and Hezbollah, gained the upper hand in the fight against the American- and Saudi-backed al-Qaeda groups, however, the importance of ISIS as a source of anti-regime resistance grew. While ISIS never had the power to challenge Damascus directly, the efforts undertaken by the Syrian coalition to defeat ISIS diverted resources needed in the larger fight. As such, the continued existence of a viable ISIS presence on Syrian soil was deemed an acceptable outcome by the United States as it sought to contain Iran’s presence on Syrian soil.

ISIS in Syria lingers on, despite the fact that U.S. military power could ensure its almost immediate elimination. The reason for the stay of execution is not entirely clear, but it could well be that the U.S. sees ISIS as a useful foil against Iran. Efforts by the United States to roll back Iran’s presence inside Syria have recently become more volatile in the wake of fiery rhetoric from senior Trump administration officials and actions undertaken by Iran to harden their positions. The American policy of Iranian rollback includes the re-imposition of economic sanctions and support for opposition groups opposed to the Iranian theocracy.

The latter point is very sensitive. This sensitivity has only been heightened by remarks from Saudi Deputy Crown Prince Mohammed bin Salman suggesting that any struggle for influence between Riyadh and Tehran ought to take place “inside Iran, not in Saudi Arabia,” and Secretary of State Mike Pompeo’s encouraging Iranian Arab minorities to rise up in opposition to the Iranian government.

When gunmen linked to ISIS attacked a military parade in the Iranian city of Ahvaz, killing and wounding dozens, the Iranian government was quick to blame the United States and Saudi Arabia, among others, and promise retaliation in kind. This prompted National Security Advisor John Bolton to declare to Iran that “there will indeed be hell to pay” if Iran or its proxies attacked the U.S. or its allies.

A few days later, Iranian rockets were launched, not against American targets in Basra, but locations in Syria linked to ISIS. While the Iranian strike was in clear retaliation for the Ahvaz attack, the rockets were emblazoned with slogans hostile to the United States, Saudi Arabia, and Israel. This made it clear that the strike was meant for a broader audience. Among those who took notice were the American forces located a mere three miles away from the targets struck by the Iranians.

Rising tensions and strong rhetoric, if not carefully managed, could easily lead to an unintended—and dangerous—escalation of hostilities. This could test President Donald Trump’s uncertain appetite for direct conflict. Moreover, the American effort to stir up an Iranian opposition could do more to unite competing power factions within Iran’s leadership, and unite Iranians behind that leadership, than to divide and weaken the Iranian polity. The Trump administration seems to operate under the delusion that Iran’s president, Hassan Rouhani, the Iranian Revolutionary Guard Corps (IRGC), and Iran’s supreme leader, Ali Khamenei, are operating in different spheres with somewhat disparate interests. U.S. efforts to drive a wedge between Rouhani and Khamenei will not only prove fruitless, but backfire, closing the door to any potential negotiations and cementing a hardline response that will have Rouhani, the IRGC, and the supreme leader united in their opposition.

The United States is engaged in a dangerous double game with ISIS that is not only hypocritical in the extreme—given the 9/11 attacks on American soil that precipitated this whole sorry affair—but counterproductive to American national security interests. It has both empowered and legitimized the very Iranian theocracy it seeks to contain.

Rather than relying on ISIS as a foil to blunt Iranian influence in Syria and terrorize its citizenry at home, the Trump administration should recognize the positive role that Iran has played in defeating ISIS. It should build upon that recognition to craft a wider regional peace process that both recognizes the realities inherent in Syria today and reduces the tensions that prompt Iran to lean forward in such an aggressive manner. Unfortunately, such thinking seems beyond the capabilities of Mike Pompeo and John Bolton. As such, America will continue to pursue poorly thought out policies with no chance of success without any thought to either cost or consequence.

Scott Ritter is a former Marine Corps intelligence officer who served in the former Soviet Union implementing arms control treaties, in the Persian Gulf during Operation Desert Storm, and in Iraq overseeing the disarmament of WMD.