PALM BEACH, Fla. — President Trump appointed Lt. Gen. H.R. McMaster as his new national security adviser Monday, picking a widely respected military strategist known for challenging conventional thinking and helping to turn around the Iraq War in its darkest days.

Trump made the announcement at his Mar-a-Lago resort, where he interviewed candidates over the holiday weekend to replace Michael Flynn, who was forced out after withholding information from Vice President Mike Pence about a call with Russia’s ambassador.

Unlike Flynn, who served as a campaign adviser last year, McMaster has no links to Trump and is not thought of as being as ideological as the man he will replace. A battle-tested veteran of both the Gulf War and the second Iraq War, McMaster is considered one of the military’s most independent-minded officers, sometimes at a cost to his own career.

The choice continued Trump’s reliance on high-ranking military officers to advise him on national security. Flynn is a retired three-star general, and Mattis a retired four-star general. John Kelly, the homeland security secretary, is a retired Marine general. Trump’s first choice to replace Flynn, Robert Harward, who turned down the job, and two other finalists were current or former senior officers as well.

McMaster, 54, made a name for himself as a young officer with a searing critique of the Joint Chiefs of Staff for their performance during the Vietnam War and later criticized the way President George W. Bush’s administration went to war in Iraq.

As a commander, he was credited with demonstrating how a different counterterrorism strategy could defeat insurgents in Iraq, providing the basis for the change in approach that Gen. David Petraeus adopted to shift momentum in a war the United States was on the verge of losing.

His challenge now will be to take over a rattled and demoralized National Security Council apparatus that bristled at Flynn’s leadership and remains uncertain about its place in the White House given the foreign policy interests of Steve Bannon, the former Breitbart News chairman who is the president’s chief strategist.

Most of the National Security Council staff is composed of career professionals, often on loan from military or civilian agencies, and they have complained privately about being shut out of their areas of expertise and kept in the dark about important decisions. Trump’s aides look on many of those holdovers from the last administration with suspicion, blaming them for leaks. The atmosphere has grown so toxic that some NSC staff members have said they feared they were being surveilled.

Peter Baker and Michael R. Gordon are New York Times writers.