By acquiescing to Turkey’s invasion of northeastern Syria on Wednesday, President Trump has opened the door to what could become a genuine nightmare for the United States and its allies: the revival of the deadly terrorist organization that called itself the Islamic State.

The danger lies not simply in the group’s sleeper cells that are still active — and that detonated three suicide bombs in the terrorists’ former capital of Raqqa on Wednesday. The larger risk comes from about 11,000 Islamic State fighters who have been detained by the Syrian Democratic Forces (SDF), the Kurdish-led militia that Trump is abandoning, and who may now try to flee.

As the SDF mobilizes to combat the Turks, security at nearly 20 makeshift prisons is likely to deteriorate, U.S. officials said. The U.S. military has said that it won’t take control, nor will European allies. Turkey’s claim that it can police the camps is hollow, given that many of these terrorists arrived in Syria after passing through Turkey.

The cascade of bad events could get worse if action isn’t taken quickly. U.S. officials fear that as security deteriorates, U.N. relief agencies may abandon control of a camp called al-Hol, which holds more than 70,000 refugees, more than 25 percent of whom are relatives of killed or captured Islamic State fighters. Riots have rocked al-Hol in recent days, and visitors say that some areas are too dangerous to enter.

U.S. analysts said Wednesday afternoon that the Turkish air attacks were broader and deeper than many had initially expected, striking targets farther east and south than the objectives Turkey had indicated to U.S. officials. Kurdish civilians were said to be fleeing Kobani after heavy shelling there, and shelling was also reported in the eastern city of Qamishli.

Here’s the appalling scenario that U.S. officials fear could unfold if the Turkish invasion isn’t a quick, limited operation, as Trump apparently hopes: As security collapses in northeastern Syria, hardened Islamic State fighters could escape the prisons, storm the al-Hol camp to reunite with their families and then renew the terrorist assault against the West that they began in 2014.

A revived Islamic State would pose a threat to the U.S. homeland — but probably a greater one to Europe, Russia and regions where the “foreign fighters” originated. Though these places are all threatened by what’s ahead, none has taken significant steps to ease the impending crisis.

This frightening risk of “snatching defeat from the jaws of victory” against the Islamic State is a result of the Trump administration’s chronic policy breakdown. This begins with Trump himself, whose erratic swings on Syria have appalled some of his closest political allies. But it extends to an interagency process so enfeebled under Trump that it has failed for months to generate clear plans for dealing with a possible Islamic State resurgence if U.S. troops should leave, as Trump demanded in December.

European nations have been nearly as guilty as the Trump administration. As I explained in May, they have refused U.S. and Kurdish pleas to repatriate some of their nationals held in the SDF-controlled prisons, or even to pay the SDF for holding them. “The European Union is in denial,” one official told me then, noting that the refugee issue was so toxic politically that no European government dared touch it.

How large is the Islamic State army-in-waiting, if the prisoners escape the camps? Gen. Mazloum Abdi, the SDF commander, gave me some numbers in an interview in Kobani in July. He said that the SDF was guarding 12,000 Islamic State fighters who were captured when the caliphate was defeated. In addition to about 9,000 Syrian and Iraqi radical Islamists, this group included 2,500 foreign fighters, Mazloum said, with about 1,000 Europeans. U.S. estimates are slightly lower, counting about 2,200 foreign fighters among 11,000 prisoners.

The prisons are rough, makeshift facilities, mostly improvised in old schoolhouses and municipal buildings. There’s one actual prison in Hasakah, which was built by the Syrian regime and commandeered by the SDF. The prisoners themselves are said to be ragged and lice-ridden, according to an American who has visited one of the sites. Two prisons have already seen riots and attempted breakouts, including one in April at a facility in Dayrik that was holding British prisoners, according to a U.S. official.

Some foreign fighters have been questioned by FBI and U.S. military interrogators, or by representatives of France, Britain and other countries from which the detainees originally traveled. In recent weeks, U.S. and other coalition officials have begun discussing what they might do if security collapsed. But there has been little coordination.

The United States has identified 50 of the most dangerous detainees and may seek to transfer them to neighboring countries, perhaps Iraq. Trump has also requested that the United States take control of two notorious prisoners, Alexanda Kotey and El Shafee Elsheikh (known in Britain as the “Beatles”), who are believed to have killed Western hostages.

For Trump, what’s unfolding now in Syria is largely a self-inflicted wound. It will be politically costly for him, but there’s a deeper problem. U.S. successes in the Middle East are too rare and precious to be squandered. But that’s what appears to be happening now in this grotesque coda to the war against the Islamic State.

Read more: