For whatever reason — legitimate or suspect — President Trump stumbled onto the correct path of America disentangling itself from wars in the Middle East.

Military strategic planners might offer valid reasons for doing so. With the fracking boom at home, America is no longer as dependent on hydrocarbon products from the region. (In fact, the entire rationale for extending costly U.S. security for those resources, since the Franklin Roosevelt administration, was questionable, given that there always have been efficient international markets to provide such commodities reasonably cheaply.)

And with the U.S. national debt standing at almost $23 trillion, and the Pentagon reorienting from fighting terrorism to countering rising threats from China and Russia, a good argument can be made for redirecting scarce U.S. dollars to the most critical needs.

What is fairly certain, however, is that none of this logic was in the president’s mind when he abruptly pulled back U.S. forces to allow the Turks to invade northern Syria and repress Syrian Kurdish forces. These Kurds had been the primary ground forces that had helped the United States decimate the militant ISIS group in that country.

After a phone conversation with Turkish President Recep Tayyip Erdogan, Trump impulsively first pulled back, rather than withdrew, a small tripwire American force, thus flashing a green light for the Turks to invade Syria to clear out the Syrian Kurds; Erdogan believes they are allied with Kurds within Turkey who are  seeking some form of self-determination. Taking advantage of the U.S. pullback, the Turkish offensive has been more robust than anticipated and threatened, likely on purpose, to make the entire U.S. military deployment untenable — leaving the Americans between Turkish troops and Kurdish forces, now assisted by Syrian government forces.

The Syrian Kurds and the Syrian government made up in the face of the Turkish onslaught — aided by Russian facilitation. There has also been news of Turkish atrocities on Kurds and an escape by hundreds of ISIS-affiliated people from a Kurdish guarded camp. In short, the Turkish invasion of Syria has turned into a debacle that was easily predictable. Although so far, the Russians, Syrian government and Turks have gained and the Syrian Kurds have lost, the situation is far from settled. Syrian and Turkish forces could very well clash directly.

More important, Trump’s subsequent decision to begin a swift and almost total U.S. withdrawal, now under fire, looks to the world as if the United States shamefully pulled the rug out from its Syrian Kurdish ally, which the United States merely used to savage ISIS and then abandoned to death. Add in reported Turkish atrocities against Kurds and potential ethnic cleansing as Turkey likely pushes the Kurds south in Syria and dumps millions Arab refugees now in Turkey into the buffer zone in northern Syria. The humanitarian crisis could be immense.

Instead of caving in to Erdogan’s demands, Trump should have negotiated a formal agreement that widened the buffer zone in northern Syria between the Turkish border and Syrian Kurdish territory. Then he could have gradually withdrawn U.S. forces, instead of endangering them by a hasty withdrawal conducted under fire in chaotic circumstances.

Withdrawal under fire is one of the most dangerous military operations imaginable. Because ISIS had been defeated, it was time for U.S. forces to come home anyway, but the group could very well take advantage of the current mayhem in northeastern Syria to resuscitate itself. A good U.S. policy goal has been turned into possible catastrophe by a whimsical decision-making process and thus concomitant slapdash execution.