WASHINGTON — President Trump has agreed to give the military about four months to withdraw the 2,000 United States troops in Syria, administration officials said on Monday, backtracking from his abrupt order two weeks ago that the military pull out within 30 days.

“If anybody but Donald Trump did what I did in Syria, which was an ISIS loaded mess when I became President, they would be a national hero,” Mr. Trump wrote. “ISIS is mostly gone, we’re slowly sending our troops back home to be with their families, while at the same time fighting ISIS remnants.”

For a president who has looked to the military for affirmation throughout his campaign and presidency and boasted about stocking his cabinet with what he called “my generals,” his decision on Dec. 19 to withdraw quickly from Syria was a significant split from his military and civilian advisers. The criticism from General McChrystal, who commanded American-led troops in Afghanistan from 2009 to 2010, echoed longstanding denunciations by former senior intelligence officials, who have warned that Mr. Trump’s approach to national security is reckless.

But during a surprise trip to Iraq last week, Mr. Trump privately told the commander of American forces in Iraq and Syria, Lt. Gen. Paul J. LaCamera, that the military could have several months to complete a safe and orderly withdrawal, according to two United States officials. And on Sunday, Senator Lindsey Graham, Republican of South Carolina, told reporters that a “pause situation” on the troop withdrawal was in effect.

By extending the timetable for withdrawal to several months, Mr. Trump stuck to his commitment to untangle the United States from yearslong military commitments but also heeded warnings from current and former military leaders of the danger of a quick exit. Defense Secretary Jim Mattis, who resigned in protest over Mr. Trump’s decision, said that leaving Syria in 30 days would jeopardize the fight against the Islamic State, betray its Syrian Kurdish-Arab allies on the ground, and cede the eastern part of the country to the Syrian government and its Russian and Iranian allies.

Nevertheless, Mr. Trump’s latest plan left open the question of whether an orderly pullout from Syria would happen. Military planners say they need about 120 days, or four months, to carry out a withdrawal that allows time to decide which equipment to move elsewhere in the region, leave behind with allies or disable to prevent it from falling into the hands of the Syrian government or Russia or Iran.

Military officials have declined to specify the timing of the departure, partly for operational security reasons and partly because many details are still quite fluid, and officials recognize that Mr. Trump could change his mind at any moment and speed up the departure.

Mr. Mattis, who will be succeeded in an acting capacity on Tuesday by his deputy, Patrick M. Shanahan, urged Pentagon employees in a farewell message on Monday to remain “undistracted from our sworn mission to support and defend the Constitution.”

When Mr. Trump first ordered a drawdown within 30 days, his position provoked an outcry, including from some of his political allies like Mr. Graham, who said that such a hasty withdrawal would leave exposed American partners such as the Kurds, who are concerned about a possible attack from Turkey. But after lunch with Mr. Trump at the White House on Sunday, Mr. Graham said he felt “a lot better” about the president’s plans.

Asked in a Fox News interview on Monday about how he had assuaged Mr. Graham, the president said, “I said, ‘You know, I never said that I’m going to rush out.’”

Mr. Trump added that the fight against the Islamic State would continue — “you can do two things at once” — and said “We have other bases in the general area. In particular, we have one in Iraq.”

Image

Mr. Trump said “ISIS is mostly gone” from Syria, where daily routines have slowly begun to return in the Islamic State’s former stronghold of Raqqa.CreditIvor Prickett for The New York Times

Military officials have scrambled to translate Mr. Trump’s shifting directives and comments into actual orders for commanders in Syria and Iraq to carry out.

On Friday, Gen. Joseph F. Dunford Jr., the chairman of the Joint Chiefs of Staff, met at the White House with Mr. Trump’s national security adviser, John R. Bolton, to get more clarity on the timing and other details of the withdrawal. Mr. Bolton is scheduled to visit Turkey and Israel in the coming days to discuss regional security issues.

General Dunford then spoke to Mr. Graham about the Syria troop withdrawal before the senator’s meeting on Sunday with Mr. Trump. Several Pentagon officials had hoped Mr. Graham could change Mr. Trump’s mind on the pullout or at least persuade him to extend the withdrawal timetable.

Col. Patrick Ryder, a spokesman for General Dunford, said in an email that the general and the senator had spoken recently, but he declined to comment on their confidential conversation and referred questions about Syria to the White House.

With most of his top advisers on vacation or having left the White House for good, Mr. Trump spent the weekend talking to allies and watching cable news coverage of the partial government shutdown.

He closely monitors the Sunday morning news shows, where General McChrystal warned that leaving Syria would effectively give up any American leverage over the war there.

“If you pull American influence out, you’re likely to have greater instability and of course it’ll be much more difficult for the United States to try to push events in any direction,” General McChrystal said, acknowledging that it was not a “big surprise” that Mr. Trump had sought to do so.

He was among the most vocal of retired military leaders who have increasingly criticized Mr. Trump, who responded by tweeting on Monday morning about the “failed generals” who oversaw American engagements in the Middle East as they continued and were extended.

“I campaigned on getting out of Syria and other places,” he wrote. “Now when I start getting out the Fake News Media, or some failed Generals who were unable to do the job before I arrived, like to complain about me & my tactics, which are working. Just doing what I said I was going to do!”

The president’s full-throated defense set him apart from past presidents, said Prof. Peter Feaver, a national security official under former Presidents Bill Clinton and George W. Bush who now teaches political science at Duke University.

“Every president has frustrations with retired military who are grading his homework from the sidelines. Think of every Fox News pundit during the Obama years and think of the so-called revolt of the retired generals in 2006 over Rumsfeld,” Mr. Feaver said.

“What’s different is that this president does so much of his grousing and thinking aloud in public on Twitter, so whereas Obama probably said something under his breath to his aides and President Bush did as well, they didn’t tweet it out for everybody to see and hear,” he added.

Mr. Trump’s aides are mindful that he needs to maintain support from rank-and-file members of the military, and they have at times pointed to support he has gotten from soldiers, demonstrated when he visited Iraq the day after Christmas, or when he visited Fort Drum in upstate New York several months ago.

In his three-paragraph farewell message, Mr. Mattis, as he has done before, cited President Abraham Lincoln’s telegram to Gen. Ulysses S. Grant on Feb. 1, 1865, as the Civil War ended: “Let nothing which is transpiring, change, hinder or delay your military movements, or plans.”

While it was difficult to avoid the possibility that Mr. Mattis was making one final veiled criticism of the commander in chief, colleagues who know the secretary well said his message was more focused on telling Pentagon and military personnel to stay the course no matter the challenges.

Eric Schmitt reported from Washington, and Maggie Haberman from New York.

A version of this article appears in print on , on Page A1 of the New York edition with the headline: Trump, Reacting to Pushback, Slows Syria Troop Withdrawal. Order Reprints | Today’s Paper | Subscribe