While General McMaster said the United States had liberated nearly all the territory held by the Islamic State, also known as ISIS, he said the American military would continue to carry out operations in Syria “until ISIS is completely defeated, population centers are stabilized and refugees can safely return home.”

That prospect seemed in doubt last week after Mr. Trump declared, “We’ll be coming out of Syria, like, very soon.” At a meeting of the National Security Council on Tuesday, which General McMaster did not attend, Mr. Trump pressed his military advisers to wrap up the campaign immediately.

The advisers, Defense Secretary Jim Mattis and the chairman of the Joint Chiefs of Staff, Gen. Joseph F. Dunford Jr., demurred, according to a person in the room. Instead, they sold the president on an alternative plan, in which troops would stay in Syria for months — though not years — to stabilize territories liberated from the Islamic State and to train local forces.

General McMaster, people who know him said, favored a deeper commitment to Syria than even Mr. Mattis or General Dunford. His colleagues said he skipped the N.S.C. meeting to attend a military awards ceremony. But his presence would likely not have helped. By that time, Mr. Trump was long past listening to his national security adviser.

The two men had a stilted relationship, even before the president decided to replace him with Mr. Bolton. They got off on the wrong foot during the debate over Afghanistan, these officials said, because General McMaster was so fervent about sending additional troops.

Mr. Trump acquiesced, but unhappily — a frustration that may have colored his views on Syria, they said. The president also bridled at General McMaster’s military-style briefings, viewing him as pedantic and condescending.

If the president’s treatment stung General McMaster, however, he did not show it. Unlike Rex W. Tillerson, who lamented the inability of people to treat one another with respect after Mr. Trump fired him as secretary of state on Twitter, General McMaster has not taken swipes at the president, either publicly or in remarks to staff members.