WASHINGTON — President Trump has instructed his military commanders to quickly wrap up the American military operation in Syria so that he can bring troops home within a few months, senior administration officials said on Wednesday. He dropped his insistence on an immediate withdrawal, they said, after commanders told him they needed time to complete their mission.

The president’s decision to keep the 2,000 troops on the ground in Syria for the immediate future came in a meeting of the National Security Council in the White House Situation Room on Tuesday, hours after Mr. Trump had told a roomful of reporters that “it’s time” to bring American forces home from a conflict that has been a crucial battlefield in the fight against the Islamic State.

At the meeting, Mr. Trump’s top military advisers told him they had drawn up plans to pull American troops out of Syria immediately. But they also presented a plan for the forces to stay longer to clean out the residual pockets of Islamic State fighters and to train local forces to stabilize the liberated territory so that the group could not regain a foothold.

“How long do you need to do that?” the frustrated president asked Defense Secretary Jim Mattis and the chairman of the Joint Chiefs of Staff, Gen. Joseph F. Dunford, according to an official present for the exchange.