WASHINGTON — President Trump’s skepticism about America’s involvement in Afghanistan was no secret to his staff. But his top national security officials were still taken aback at a meeting in the Situation Room on July 19, when an angry Mr. Trump began ripping apart their latest proposal to send thousands of additional American troops to the country.

“We’re losing,” the president declared, according to a person who was in the room. The plan, he complained, was vague and open-ended, with no definition of victory. “What does success look like?” he asked.

The day before that meeting, Mr. Trump had invited four soldiers who had served in Afghanistan to the White House for lunch. His exchanges with these enlisted men, an official said, left him sober about the prospects for turning around a war that has dragged on for nearly 16 years. He showed up the next day determined to ask hard questions.

On Monday night, Mr. Trump finally put forward a broader strategy for Afghanistan, one that would require thousands more American troops but place more conditions on the Afghan government. His decision, several officials said, was less a change of heart than a weary acceptance of the case, made during three months of intense White House debate by the military leaders who dominate his war cabinet.