WASHINGTON — The Pentagon recently began drawing up plans for an abrupt withdrawal of all U.S. troops from Afghanistan in case President Donald Trump surprises military leaders by ordering an immediate drawdown as he did in Syria, three current and former defense officials said.

The contingency planning is ongoing, the officials said, and includes the possibility that Trump orders all U.S. troops out of Afghanistan within weeks. Officials cautioned, however, that the planning is a precaution and there is currently no directive from the White House to pull U.S. troops out of Afghanistan.

One of the officials called it "prudent planning."

Another official described the president's current approach to Syria as "a dress rehearsal" for what could happen in Afghanistan.

Trump has long threatened to withdraw all American forces from Afghanistan, but his repeated emphasis in recent weeks on the need to end all foreign wars has infused a new sense of urgency into the renewed Pentagon effort, officials said.

The president's abrupt policy shift on Syria also has shown he's willing to follow through on his threats of troop withdrawals, though his advisers have been able to talk him out of such moves in the past. And it coincides with an increasing focus on the 2020 election.

"I got elected on bringing our soldiers back home," Trump told reporters Monday.

To underscore the point, the president said the biggest applause he received during a campaign rally in Dallas last week was when he talked about building a wall on the U.S.-Mexico border and bringing American troops home. "When I said, 'We're bringing our soldiers back home,' the place went crazy," Trump said.

Lt. Col. Thomas Campbell, a Department of Defense spokesperson, said the Pentagon regularly evaluates troop numbers overseas and provides advice to the president.

"The Defense Department does not have orders to draw down troops in Afghanistan and our mission has not changed," Campbell said.

"U.S. force levels in Afghanistan remain conditions-based and will continue to reflect the level required to execute our mission," he said, which includes "ensuring Afghanistan is never again used as a safe haven for terrorists who threaten the United States, our allies or our interests."

When Defense Secretary Mark Esper was asked during a surprise visit to Afghanistan on Monday whether Trump could pull all U.S. troops out of the country, Esper compared the situation to Syria, explaining they are very different missions.

"Very different situations, very different adversaries if you will, very different level of commitment. Very clear policy direction on one," Esper said. "All these things should reassure Afghan allies and others they should not misinterpret our actions in the region in the recent week or so in regard to Syria and contrast that with Afghanistan."

The commander of all U.S. and NATO troops in Afghanistan, Gen. Scott Miller, said he has already streamlined the U.S. presence in Afghanistan over the past year, bringing 2,000 troops out.

"Where I sit right now as I make recommendations through my military chain of command," he said, "I'm confident we have right capabilities to reach objectives, as well as continue to train, advise and assist throughout the country."

A senior administration official said the president currently is planning for a reduction in the number of troops in Afghanistan in coming months.

Ending wars like the one in Afghanistan was one of Trump's chief campaign promises in 2016, and administration officials have privately expressed concern that as the 2020 election approaches, he'll be more likely to follow through with threats of troop withdrawal, as he did last week in Syria.

Trump has made clear to his advisers that he wants to pull all U.S. troops out of Afghanistan by the 2020 election, NBC News reported in August.

The collapse of Afghan peace talks, and the 2020 campaign, have raised concern among some administration officials of an increased likelihood that Trump would order a swift withdrawal, officials said.

After Trump threatened in December 2018 to immediately withdraw all troops from Afghanistan — and shut down the U.S. embassy in Kabul — aides convinced him that if he instead let the peace talks continue, the U.S. would leave in 2020.

But administration officials have said the president is expected to move forward with what one official described as "a token withdrawal" of U.S. troops from Afghanistan by the end of this year.

Any reduction of American forces had previously hinged on progress in the peace talks with the Taliban.

Negotiations on a peace deal with the Taliban to end the Afghanistan war collapsed last month after Trump called off nascent plans for a meeting at Camp David.

U.S. military officials expect the president still to order the withdrawal of at least several thousand U.S. troops by the end of this year, leaving almost 9,000 U.S. troops there. U.S. military officials say they can continue counterterror and training missions with a scaled-back force of that size. The officials stressed that the president has not made a final decision on how many troops to withdraw this year.