President Donald Trump said on December 19 that the terrorist group ISIS was defeated in Syria and that US troops would therefore leave.

The situation is much more complicated.

The US wants Turkey to hold the line and take on the remnants of ISIS, which is not totally defeated.

It also wants assurances that Turkey will not attack Kurdish militants, which Turkey considers terrorists, in Syria.

Trump's national security adviser, John Bolton, went to Turkey this week to secure these assurances.

But Turkish President Recep Tayyip Erdogan on Tuesday refused to agree to Bolton's conditions and said Bolton "made a serious mistake."

It is not clear how Trump will be able to deliver on his promise if the US and Turkey cannot agree.

President Donald Trump's controversial plan to pull US troops out of Syria is starting to fall apart already, because Turkey — which the US wants to step up when it leaves — won't agree to the White House's terms.

The cracks in the plan became evident on Tuesday when Turkish President Recep Tayyip Erdogan publicly rebuked Trump's national security adviser, John Bolton, who is visiting the country to insist that Turkey fulfills the criteria for a US withdrawal.

Bolton told reporters on Sunday that he would seek Turkey's assurance that it will not attack Kurdish militants in northern Syria after the US is gone.

US forces in Syria fight alongside the Kurdish YPG militia, which Turkey considers a terrorist group. Here, a YPG flag flutters in Al-Darbasiyah, on the Syrian-Turkish border, in March 2017. REUTERS/Rodi Said

US forces in Syria are fighting alongside the People's Protection Units, or YPG, a Kurdish militia in Syria.

Turkey considers YPG forces to be terrorists because of their connection to the Kurdistan Workers' Party, a group in Turkey that Ankara considers a terrorist organization.

The US believes that its withdrawal from Syria could leave YPG fighters vulnerable to Turkish attacks.

Bolton said on Sunday, according to the BBC: "We don't think the Turks ought to undertake military action that is not fully coordinated with and agreed to by the United States."

He said the conditions were "at a minimum so they don't endanger our troops, but also so that they meet the president's requirement that the Syrian opposition forces that have fought with us are not endangered."

US Marines fire 120mm mortars in support of Operation Inherent Resolve in September in Syria. The US believes a withdrawal from Syria could leave YPG fighters vulnerable to Turkish attacks. Cpl. Gabino Perez/USMC

Erdogan on Tuesday refused to give such assurance and slammed Bolton's thinking as "a serious mistake."

He told his AK Party at the Turkish Parliament in Ankara, according to Reuters, that "if they are terrorists, we will do what is necessary, no matter where they come from."

"Bolton has made a serious mistake, and whoever thinks like this has also made a mistake," Erdogan added. "It is not possible for us to make compromises on this point."

According to Ragip Soylu, the Turkey correspondent at the Qatari-funded news organization Middle East Eye, Erdogan added that "saying that Turkey targets Syrian Kurds, which is a lie itself, is the lowest, most dishonorable, ugliest, most banal slander ever."

Read more: Trump says 'the generals' asked for more time in Syria, but he said 'Nope' because 'We've knocked them silly'

Trump's decision to withdraw from Syria has been controversial. Evan Vucci/AP

Erdogan's remarks appear to have opened up a new rift between the US and Turkey.

Bolton, who is in the Middle East this week, will leave Turkey on Tuesday without meeting Erdogan at all, The Associated Press reported.

His Turkish counterpart, Ibrahim Kalin, abruptly canceled a scheduled joint press conference after their meeting, Agence France-Presse reported.

On December 19, Trump announced his decision to pull all 2,000 troops out of Syria, claiming that it was because "we have defeated ISIS in Syria" — contradicting analyses from the US-led coalition that the "mission in northeast Syria remains unchanged."

The president appeared to walk back his claim the next day, saying in a tweet: "Does the USA want to be the Policeman of the Middle East, getting NOTHING but spending precious lives and trillions of dollars protecting others who, in almost all cases, do not appreciate what we are doing? ... Time for others to finally fight."

The decision to withdraw from Syria has been controversial; James Mattis, the former US defense secretary, and Brett McGurk, the top US official leading the 79-nation fight against ISIS, both resigned over it.