President Trump has directed the Pentagon to withdraw nearly half of the more than 14,000 troops deployed to Afghanistan, U.S. officials said Thursday, a move that many of Trump’s senior advisers and military officials have warned will plunge the country further into chaos.

The order comes on the heels of Trump’s announcement that he will be withdrawing all 2,000 U.S. troops from Syria, a surprise decision that the president made against the counsel of his top advisers and without warning any of the allies who have fought alongside American forces in the battle there against the Islamic State.

The Afghanistan directive also comes as the United States attempts to negotiate a peace deal with the Taliban, potentially undercutting leverage that American diplomats have. It marks a significant departure from Trump’s August 2017 decision to slightly increase the number of U.S. troops there and keep them in place with conditions on the ground dictating withdrawal.

Trump’s moves on Syria and Afghanistan prompted the resignation Thursday of Trump’s Pentagon chief, Jim Mattis, who said in a letter to the president that Trump had the right to find a defense secretary whose views were better aligned with his. Mattis, a retired four-star Marine general who was among the first combat leaders in Afghanistan, opposes a hasty withdrawal from both countries.

The issue came up at a White House meeting of Cabinet-level officials this week, according to one adviser to the president, who spoke on the condition of anonymity due to the sensitivity of the issue. The president pressed White House national security adviser John Bolton to make the moves, and Bolton is resisting, the adviser added.

Outgoing White House Chief of Staff John F. Kelly, a retired Marine general, also has opposed Trump’s impulses on both countries but no longer has any lasting power with the president.

A senior administration official, also speaking on the condition of anonymity, said that other U.S. officials are still trying to change Trump’s mind, and it is unlikely a decision on it will be announced Friday.

The news, first reported Thursday by the Wall Street Journal, is certain to worry senior officials in Afghanistan, who already are battling deteriorating security in the country despite the existing U.S. military presence there. And it will be greeted wearily by many senior U.S. military officers, who have launched more airstrikes in Afghanistan this year than in any during the 17-year-old war, the longest in American history.

The top U.S. military spokesman in Afghanistan, Col. David Butler, said he did not have comment right now. Defense officials in the United States either did not respond to the reports, or said they had no information.

A cut to about 7,000 U.S. troops in Afghanistan would likely mean the United States abandons much of its mission advising Afghan forces, with emphasis remaining on counterterrorism operations and securing a few military installations, such as Bagram Airfield.

Senior U.S. military officials have repeatedly warned that leaving Afghanistan could have dangerous consequences in the United States.

Marine Gen. Joseph F. Dunford Jr., the chairman of the Joint Chiefs of Staff, said Dec. 6 that in his judgment, withdrawing would “give terrorist groups the space within which to plan and conduct operations against the American people, our homeland and our allies.”

Mattis, speaking in August, said that the U.S. military remains in Afghanistan to ensure American security at home.

“That involves the Afghan people being in control of their own future,” Mattis said. “This is why we talked about an Afghan-led, Afghan-owned reconciliation process. We believe that the best way to get there is to ensure the Taliban recognizes they can’t win on the battlefield; they must negotiate.”

Army Gen. Austin “Scott” Miller took over as the new U.S. commander in Afghanistan in September, and has mainly remained quiet in the media while assessing conditions on the ground. He survived an attack in Kandahar province in October that killed two senior Afghan officials and wounded an American senior officer, Brig. Gen. Jeffrey Smiley.

Miller, speaking with NBC News after the attack, said that he assesses that neither the U.S.-led coalition backing the Afghan government nor the Taliban can presently win the war through military force. He also said that he does not feel pressure from Washington to show results.

“I naturally feel compelled to try to set the conditions for a political settlement,” Miller said in the interview. “So pressure from that standpoint, yes. I don’t want everyone to think this is forever.”

Speaking in his confirmation testimony in June, Miller told senators his initial belief was that the United States had the correct number of troops in Afghanistan.

He said the continued mission there was crucial to protecting U.S. security, a lesson he learned in his counterterrorism work of over a decade and a half.

“I’ve learned these groups thrive in ungoverned spaces,” Miller said. “And I've also learned when we maintain pressure on them abroad, they struggle to organize and build the means to attack us. Our core goal in Afghanistan is to ensure terrorists can never again use the country as a safe haven to threaten the United States or other members of the international community.”

Afghan officials and observers have been increasingly concerned that the United States may negotiate a hasty separate deal with the Taliban that makes concessions that Afghans consider dangerous for their security and the democratic gains made over the past 17 years.

While Taliban spokesmen have repeatedly said that the withdrawal of all foreign troops and bases is their most imperative demand, Afghan officials have always urged that an American military presence be maintained, in part because of the ongoing threat of violent attacks and bombings by the separate Islamic State group.

A spokesman for Afghan President Ashraf Ghani said on TV that a U.S. troop reduction “will not affect the security situation in the country.” The spokesman, Harun Chakhansuri, said that “most of the U.S. forces which will possibly be withdrawn from Afghanistan are engaged in a training and advising mission for Afghan forces, and Afghan forces are capable of defending the country.”

Wahid Mojdah, an analyst with ties to the Taliban, warned, however, that the withdrawal could be a real problem for the country.

“Unless there is a comprehensive plan for troop withdrawal and an ongoing program for the future, this would be very dangerous for Afghanistan and the region,” he said.

Other analysts suggested that by preempting the negotiations already underway with the Taliban insurgents and unilaterally meeting one of their top demands, Trump’s move could undermine the peace talks, give the Taliban a strong upper hand and throw the country’s political future into chaos.

Michael Kugelman, an analyst at the Woodrow Wilson International Center for Scholars in Washington, called Trump’s decision to sharply reduce troops “a major propaganda coup for the Taliban. It’s gotten the foreign troop withdrawals it has always wanted, and without having to give up anything in return.”

For his part, Davood Moradian, executive director of the Afghan Institute for Strategic Studies, said that a U.S. military retreat from Afghanistan would be a humiliating tragedy and that history would judge Trump as having overseen “the demise of America’s global role, endangering its credibility and honor.”

“The U.S. intervention was in response to the tragedy of 9/11, but its military disengagement would bring similar consequences” as the Soviet troop withdrawal from Afghanistan” 30 years ago, he said, predicting “a revival of hybrid civil and regional conflict, mass emigration, and the jihadist’s claim of defeating another infidel superpower.”