Turkish President Recep Tayyip Erdogan in Ankara on March 6. (Umit Bektas/Reuters)

TURKEY’S MILITARY victory over Kurdish forces in the northern Syrian town of Afrin was costly. It took eight weeks, cost several thousand lives and displaced several hundred thousand civilians. The town itself, which was predominantly Kurdish, was looted after Turkish forces moved in. Finally, the fight deepened the rift between the Trump administration and Turkish President Recep Tayyip Erdogan, who celebrated his win by boasting that his forces would advance across northeastern Syria — which could bring them into conflict with U.S. troops.

Mr. Erdogan, who seems to grow steadily more power-drunk, is likely bluffing. But the United States now faces an acute strategic problem in Syria: how to preserve its de facto control over a large stretch of territory east of the Euphrates River without going to war against a NATO ally. A continued U.S. presence is needed to complete the defeat of the Islamic State, prevent Iran from consolidating control over the country and leverage an acceptable settlement to Syria’s civil war. But preserving the alliance with Turkey is also a vital U.S. interest.

The easy way out of the dilemma is to cave in to Mr. Erdogan. But that would only stir up more trouble for the Trump administration, both in Syria and in Turkey.

The focus of the allies’ dispute is the American partnership with the Syrian Democratic Forces (SDF), which are led by a Syrian Kurdish movement allied with Kurdish militants in Turkey. The SDF was crucial to the defeat of the Islamic State in eastern Syria, and it could help to stabilize that part of the country under a new civilian administration. Yet Mr. Erdogan, who until 2015 was committed to peace with the Kurds, insists the Syrian Kurds are terrorists, and is trying to drive them out of territories near Turkey.

The fraught discussion between the allies seemed to improve after a long conversation between Mr. Erdogan and Secretary of State Rex Tillerson last month. The Turks subsequently said an agreement had been reached to evacuate SDF forces from another town, Manbij, which is predominately Arab. But Mr. Tillerson has since been dismissed, and the State Department said last week that no deal had been finalized.

It’s possible to imagine a compromise settlement under which Kurdish forces were relocated east of the Euphrates and U.S. troops remained in Manbij to help protect civilians. But Mr. Erdogan seems to want more — like Russia and Iran, he probably would like to push the United States entirely out of Syria. The Trump administration must reject that option, which would require it to abandon the forces who helped to defeat the Islamic State — and are still needed to prevent its resurgence.

Moreover, relations with Turkey cannot be mended unless Washington demands more from Mr. Erdogan. As a start, Mr. Trump should insist that Turkey release U.S. citizens it is holding as de facto hostages, and that domestic repression be relaxed. Mr. Erdogan should be pushed to reopen peace negotiations with the Kurds. If he continues on his present, reckless path, a rupture in the alliance is inevitable, sooner or later. Syria’s Kurds should not be sacrificed to prevent it.