For nearly two years, the approach produced dividends. The Pentagon strengthened the war effort in Afghanistan, winning an increase in troops against President Trump’s initial instincts. The fight against the Islamic State continued apace in Syria and Iraq, and the military won extra leeway to make decisions on the battlefield. Funding from Congress, long crimped by budget caps, began flowing anew.

AD

AD

Last week, much of that came crumbling down, opening a period of uncertainty about how and when Trump will choose to employ force.

Against the advice of his generals, the president ordered an immediate withdrawal from ­Syria. Military and civilian leaders from across the government had spent months making the case for continued involvement, as partner forces struggled to fully eliminate the Islamic State.

In the same meeting during which Trump issued his order on Syria, he decided to remove nearly half of the American troops in Afghanistan. Gen. Joseph F. Dunford Jr. — chairman of the Joint Chiefs of Staff and the president’s top military adviser — wasn’t even there, according to people familiar with the situation.

AD

Two days later, Mattis had tendered his resignation, citing irreconcilable differences between Trump’s worldview and his own.

AD

Making his resignation letter public, the retired Marine general made clear that his departure was driven by principle — a moment of defiance for an official whose tenure was marked by his studied silence on a growing list of policy disagreements.

The fallout from the resignation continued Sunday. With coverage of Mattis’s departure painting Trump in a bad light, the president moved up the Pentagon chief’s departure by two months and tapped his deputy, Patrick Shanahan, to become acting defense secretary on Jan. 1.

From his first week in office, Trump’s style and choices have grated on many among the military brass.

AD

Setting the tone for what would come, the president chose the Pentagon’s Hall of Heroes — the department’s most hallowed space — for the hastily arranged January 2017 ceremony to sign his travel ban, suggesting to the world that the deeply divisive decree had the military’s backing.

AD

Peter Feaver, an expert on civilian-military relations at Duke University, said any president would have struggled to win over the Pentagon after years of budget cuts and what military officials had seen as micro­management under President Barack Obama.

“Then you had Trump, who brought in a whole other dynamic of friction-generating behavior,” Feaver said.

Some of it has been about style. For many senior officers brought up in an organization that stresses discipline and honor, it has been jarring to see a commander in chief insulting allied leaders or wading into personal feuds. “He’s taboo-breaking, whereas the military is about respecting taboos,” Feaver said.

AD

It has also been about substance. Current Pentagon leaders rose through the ranks in the post-Sept. 11, 2001, era, when NATO nations sent thousands of troops to fight alongside the United States. Trump, meanwhile, voiced doubts about the value of the alliance, threatened to abandon the partnership with South Korea and questioned whether the military should remain in the Middle East.

AD

For a while, Mattis was able to reconcile his own internationalism with Trump’s “America First” beliefs. As the president endorsed the Pentagon’s shift of emphasis toward Russia and China and filled military coffers, Mattis likened the president’s worldview to traveling on a plane and putting on your oxygen mask before helping others, several people recounted.

Defense officials have also grappled with a lack of predictable decision-making. They have repeatedly been blindsided by the president’s Twitter pronouncements: ending military aid to Pakistan, banning transgender troops, creating a Space Force.

AD

Most worrisome for some military leaders, however, is the fear that their tradition of partisan neutrality — fundamental to maintaining public support — could be under threat.

As the Pentagon prepared to strike Syrian President Bashar al-Assad’s military in 2017 in response to its use of chemical weapons, Trump began asking, “Who is my military guy who is going to sell this on the Sunday shows?” according to a person familiar with the discussions who, like others, spoke on the condition of anonymity to discuss internal discussions. When Mattis and other Pentagon leaders demurred, then-national security adviser H.R. McMaster appeared on “Fox News Sunday.” McMaster wore a suit instead of his general’s uniform.

AD

When Trump pulled the military into other politically divisive initiatives, including plans for a massive military parade and the deployment of active-

duty troops to the southern U.S. border ahead of the midterm elections, Pentagon officials got in line despite their private reservations.

AD

Asked about the border mission, Dunford said he was duty-bound to execute any lawful order, no matter his personal beliefs.

“The American people would not want generals to be making policy decisions and wouldn’t want generals to determine when we should use force,” Dunford said at a Washington Post event this month. “I think it would be problematic were generals to start to make decisions based on one political party or another being in office and say, ‘No, I don’t really like that, so I’m not going to do that.’ ”

AD

Crystallizing the view of many uniformed leaders, Dunford said he would be unlikely to resign out of principle. “My code tells me that lance corporals and [privates] and seamen can’t resign when they’re told what to do,” he said.

Kori Schake, deputy director general of the International Institute of Strategic Studies and co-editor of a book with Mattis, said research shows that, despite such efforts, public attitudes about the military are growing more politicized.

AD

“The president is rapidly corroding the norms of civil-

military relations that create the public respect for our military,” Schake said.

For his part, Mattis has sought to isolate the Pentagon from the political maelstrom by eschewing the spotlight and rarely appearing on camera. Given his disagreements with Trump on a host of issues, a crucial part of his strategy was to avoid conflict with his boss.

AD

Across the military, leaders took a cue from the Pentagon chief, declining speaking appearances.

“Everybody in the Defense Department, including the out­going secretary, had trimmed their sails significantly in order not to draw the president’s tempestuous ire,” Schake said. “One of the costs of the way that Jim tried to maintain his influence with the president is not making a public case about why we have Americans in harm’s way in ­Syria, Iraq and Afghanistan.”

AD

Last week’s Syrian withdrawal announcement has prompted concern about whether military and civilian leaders should have realized earlier that Trump eventually was bound to follow his instincts on Syria and other foreign policy issues. While opponents of a Syria exit were able to delay his decision for months, the president’s desire ultimately bubbled over.

AD

“Trump has been very clear about the things he wants to do, and while his advisers may sort of push and pull him in various directions, at the end of the day he has largely prevailed,” said Mara Karlin, a former Pentagon strategist during the Obama administration and executive director of the Merrill Center for Strategic Studies at Johns Hopkins University.

That the Pentagon was able to get Trump to increase the number of troops in Afghanistan and stay the course in Iraq and Syria for half of his first term is noteworthy, she said.

“In some ways, the story may be how amazing it is that we decided to do this for so long,” Karlin said.

How the Pentagon will put its recent orders into practice remains to be seen.

Already, there are suggestions the military could try to continue Special Operations missions in Syria from neighboring Jordan and Iraq, and continue its air campaign against the Islamic State. The partial withdrawal from Afghanistan still hasn’t been announced publicly, opening a chance for those who support a more robust presence to try to change the president’s mind.

Trump will also have the opportunity to make his mark on the military by selecting a new cadre of Pentagon leaders.

He already surprised the top brass this month by announcing his pick to replace Dunford as chairman of the Joint Chiefs. His selection of Army Chief of Staff Gen. Mark Milley, an outspoken, connected officer, nearly a year before Dunford was scheduled to retire defied the recommendation of Mattis and raised the possibility that Dunford will not serve his entire term.

In addition to Milley, Trump will have the chance to appoint three chiefs of the military branches.

Retired Army Lt. Gen. David Barno, who was head of Combined Forces Command-Afghanistan from 2003 to 2005, said the current crop of military leaders had successfully steered the Trump administration toward a “middle ground” on key alliances, conflicts and more.