In the run-up to the election, President Trump’s tweet saying that all U.S. troops in Afghanistan should be “home by Christmas!” raised alarm among senior U.S. officials who had been working on a more gradual withdrawal.

The existing plan, tied to precarious negotiations with the Taliban insurgent group to sign a peace deal with the Afghan government, had not yielded the progress that American officials wanted. While the Pentagon was on its way to reducing the number of troops to fewer than 5,000 this month, negotiations appeared to stall and the Taliban continued to launch attacks across the country.

After consulting with senior military officers, Defense Secretary Mark T. Esper sent a classified memo to the White House this month expressing concerns about additional cuts, according to two senior U.S. officials familiar with the discussion. Conditions on the ground were not yet right, Esper wrote, citing the ongoing violence, possible dangers to the remaining troops in the event of a rapid pullout, potential damage to alliances and apprehension about undercutting the negotiations.

President Trump fired Defense Secretary Mark T. Esper in a Nov. 9 tweet, marking the fourth Pentagon chief the president has let go during his administration. (Reuters)

Days after Trump lost his reelection bid, he fired Esper. Trump, refusing to concede the election, has since allowed a purge of other senior political appointees serving under Esper, with several hardened loyalists to the president taking their place.

This account of the deliberations over Afghanistan in the waning days of the Trump administration is based on interviews with 21 current and former U.S. and Afghan officials, many of whom spoke on the condition of anonymity because of the sensitivity of the issue. Trump’s relationship with Esper soured months ago over several issues, but some in the president’s orbit said Trump’s frustration with what he sees as an entrenched military resistant to his goals played a role. Others denied that Esper’s position on Afghanistan had anything to do with it.

The turmoil in the Pentagon comes amid deep uncertainty about how the time between now and Inauguration Day, Jan. 20, will play out. While some Republicans have congratulated former vice president Joe Biden on his victory, Trump administration officials have signaled that they will fight to stay in office.

In the meanwhile, time has all but run out for Trump to fulfill his often-stated desire to end America’s 19-year-old war, the longest in U.S. history.

The situation is highlighting a long-standing rift between the isolationist factions of the Trump administration and more traditional conservatives and prompted speculation that the Trump loyalists installed at the Pentagon may attempt to force through changes.

Colin Jackson, who served as a senior Pentagon official overseeing Afghanistan early in the Trump administration, advocated against a withdrawal now.

“We don’t have a single example where pulling the plug has gone well — Vietnam, Iraq,” he said. “Not one.”

One former senior White House official said it is not possible for the United States to remove all troops “without crushing the coalition there.”

“We can get down to maybe 4,500,” the official said. “But we cannot be at zero.”

Sen. Rand Paul (R-Ky.), who has advocated a swift and total withdrawal, stepped into the debate Wednesday.

“Reminder to those saying withdrawing troops may cause a ‘clash’ with Generals/Pentagon: there is only one Commander in Chief, it is @realDonaldTrump and when he orders the troops out of Afghanistan, the only proper answer is ‘Yes sir,’ ” he tweeted.

The new appointees include Christopher Miller, who leapfrogged several more senior administration officials in the Pentagon to become acting defense secretary; Kash Patel, a former aide of Trump ally Rep. Devin Nunes (R-Calif.); and Douglas Macgregor, a retired Army colonel who has often called for the end of the war in Afghanistan.

Miller, most recently the director of the National Counterterrorism Center, and Patel have both worked at length with national security adviser Robert O’Brien, who has disagreed publicly in recent weeks with Gen. Mark A. Milley, the chairman of the Joint Chiefs of Staff, about what the administration’s plan entails.

During a speech last month, O’Brien announced at an event in Las Vegas that the United States “will go down to 2,500” by early next year in Afghanistan.

Milley dismissed those remarks during an interview with NPR as “speculation” and said the United States wanted to end the war “responsibly” and “deliberately.”

O’Brien then doubled down. “When I’m speaking, I’m speaking for the president, and I think that’s what the Pentagon is moving out and doing,” he said.

Jonathan Rath Hoffman, a Pentagon spokesman, said in a statement Friday that Miller is working with Trump and the entire national security team “on meeting our Afghanistan strategic objectives.” In calls and meetings with NATO partners this week, Miller “consistently assured them of our process with respect to Afghanistan,” Hoffman added.

One former senior government official who occasionally talks to the president said he thought it was possible that Trump may order cuts to 2,500. The official questioned the wisdom of that, saying it gives away “leverage in the peace negotiations.”

Miller is seen by others in the administration as open to cutting deeper than 4,500. In a memo to the Defense Department released on Friday night, he said that the war against al-Qaeda has been long and is not over, but that it is time “we transition our efforts from a leadership role to a supporting role.”

“We are not a people of perpetual war — it is the antithesis of everything for which we stand and for which our ancestors fought,” Miller wrote. “All wars must end.”

He made no mention of the Pentagon’s shift over the past few years to focus first on security concerns raised by China.

On Friday he spoke to NATO Secretary General Jens Stoltenberg about issues that include Afghanistan, NATO spokesperson Oana Lungescu said in an email.

“We have been in Afghanistan for almost 20 years, and no NATO ally wants to stay any longer than necessary,” Lungescu said. “At the same time, we want to preserve the gains made with such sacrifice, and to ensure that Afghanistan never again becomes a safe haven for terrorists that can attack the United States or any other NATO ally.”

Partner nations have made clear to the Trump administration that they cannot and will not remain in Afghanistan if there is a complete U.S. withdrawal, but have been told by Miller that there has been no change in policy and there will be no surprises.

The Afghan government has not been informed of a change to the U.S. withdrawal timeline, according to an Afghan official. President Ashraf Ghani’s office did not immediately respond to requests for comment, and U.S. Forces Afghanistan referred questions to the Pentagon.

The possibility of a rapid withdrawal comes as violence has spiked in Afghanistan. The latest government watchdog report states that attacks by the Taliban and other anti-government groups had recently spiked 50 percent. In the regions hardest hit, local officials are warning that if the withdrawal timeline is accelerated, government forces might be unable to defend themselves.

“If we didn’t have American airstrikes, the Taliban would be in Lashkar Gah today,” said Sher Mahmad Akhunzada, a member of Parliament, referring to Helmand’s provincial capital.

One U.S. official said the time frame associated with a potential drawdown decision would inform the logistics of that process and “how much more dangerous it would be rather than a fully planned and well-executed withdrawal.”

The official said that while there is “some indication” that the Taliban has ordered its fighters not to attack American personnel, that might not hold true during a final withdrawal. As U.S. personnel make rapid air and ground movements to prepare for their departure and remaining facilities becoming more scarcely manned, “it would be more difficult to get out safely and rapidly,” the official said.

A rushed exit would also likely mean leaving behind valuable equipment. Some large hardware containing sensitive technology, like the UH-60 Blackhawk, can fit in the back of a cargo plane. But other sensitive items would need to be destroyed in place.

Edward Dorman, a retired major general who served as U.S. Central Command’s director for logistics from 2016 to 2018, said that if an American departure is authorized, some U.S. bases or facilities would probably be turned over to the Afghan military, as long as officials were confident they would be maintained and not lost to the Taliban.

Even if a handover does occur, it would require significant steps to prepare. Bases that weren’t handed over to the Afghan military would need to be torn down and, either way, environmental remediation would likely be required.

Biden has not directly addressed the U.S.-Taliban agreement signed in February, leading to the partial withdrawal of troops that is now underway. But he has said he plans to reduce the number of troops to “several thousand” to ensure that neither al-Qaeda nor the Islamic State is in a position to launch attacks against the United States.

Michele Flournoy, a former top Pentagon official who is seen as a leading candidate for defense secretary under Biden, has said that a “precipitous” withdrawal would undermine peace and that a counterterrorism force should remain in Afghanistan at least until a comprehensive agreement between the Taliban and Afghan government is in place.

The U.S.-Taliban deal promises full U.S. withdrawal by the end of April if its conditions, including Taliban negotiations with the Afghan government and a reduction in violence, have been met. It contains no provision for a residual U.S. counterterrorism force.

Asked whether Biden plans to continue with the deal, the withdrawal and the current U.S. envoy to the peace talks, Zalmay Khalilzad, a Biden spokesperson said Friday that “President-elect Biden laid out an extensive foreign agenda over the course of the campaign and looks forward to delivering on it once in office.”

The spokesperson, who was not authorized to speak on the record, said that no more details would be offered at this time. Biden, he said, “firmly believes in the principle that there must be only one president at a time guiding our country’s foreign policy and national security as he is focused on preparing to govern.”

Ellen Nakashima, Greg Jaffe, Josh Dawsey and Julie Tate contributed to this report.