After President Trump tweeted on Aug. 30 that "talking is not the answer," Defense Secretary Jim Mattis denied that the United States was out of diplomatic solutions with North Korea. (Reuters)

Away from the cameras and apart from the nonstop drama of the White House, Defense Secretary Jim Mattis has come to play a role unlike any other Cabinet member.

The retired Marine general has become a force for calm, order and, in the eyes of the president’s critics, quiet resistance to some of President Trump’s most combative and divisive instincts.

In perhaps his greatest political feat, Mattis has maintained this air of independence without directly provoking a president who demands absolute loyalty.

The latest example came Wednesday morning when Trump vented his frustrations with North Korea after its latest missile launch.

“Talking is not the answer!” Trump tweeted only a few hours before Mattis met at the Pentagon with Song Young-moo, South Korea’s defense minister, and delivered a very different message to reporters.

Three Cabinet secretaries have appeared to distance themselves from President Trump in the wake of his response to the violence in Charlottesville. (Bastien Inzaurralde/The Washington Post)

“We’re never out of diplomatic solutions,” Mattis said.

On Tuesday night, Mattis seemed again to be in mitigation mode when he announced that he would be pulling together a “panel of experts” to provide advice on how to implement Trump’s ordered ban on transgender troops.

Trump announced the ban last month in a series of tweets that caught the military’s top brass largely by surprise. By contrast, Mattis’s statement promised an exhaustive study and also seemed to leave the door open to allowing some transgender troops who are serving to stay in uniform.

Perhaps the most striking example of Mattis’s inclination to tamp down deep political divisions came in the wake of the recent violence in Charlottesville. Mattis was recorded in a video uploaded to Facebook speaking off the cuff to a small group of American troops in Jordan. “Our country, right now, it’s got problems that we don’t have in the military,” Mattis told them. “You just hold the line until our country gets back to understanding and respecting each other and showing it.”

The comments were interpreted by some as a critique of Trump’s leadership.

Mattis and his top advisers blanch at suggestions that he is resisting the wishes of his commander in chief. As defense secretary, Mattis has steered away from the public spotlight, avoiding Pentagon news conferences and on-camera interviews. And he has expressed frustration with those who scrutinize his remarks for signs of disagreement with Trump.

In his often terse public statements, the defense secretary has repeatedly noted that he is not the ultimate decision-maker on matters of military or foreign policy.

“The American people elected the commander in chief,” Mattis said after Trump’s tweets last month on the new transgender policy. “They didn’t elect me. . . . He has that authority and responsibility. So that was fully within his responsibility.”

Mattis is far from the only senior Trump administration official who has seemed to be at odds with the president of late. Secretary of State Rex Tillerson and National Economic Council Director Gary Cohn both distanced themselves from Trump’s remarks following the Charlottesville violence for their failure to unequivocally condemn hate groups.

“The president speaks for himself,” Tillerson said coolly of Trump’s public statements. Tillerson and Cohn’s comments both fueled new tensions with the White House and fed speculation that they could soon be gone from the administration.

But Mattis’s deft political touch has surprised many who watched him fall out of favor with the Obama White House. As a four-star general, Mattis pushed for the Obama administration to take a harder line against Iran’s destabilizing behavior in places such as Yemen, Iraq and Syria. Ultimately, his aggressive style alienated the White House and the president he was serving.

In the Trump administration he has managed to press his differences without provoking a backlash.

In many instances his opposing view seems shaped by his more than four decades of military service in the Marine Corps than any overt political disagreement with the president.

Some analysts speculated, for example, that Mattis’s slow-rolling resistance to Trump’s order on transgender troops may be motivated by a deeply held military bias for consistency and continuity over sudden shifts in policy.

“He’s clearly saying he’s not going to be a political agent of change inside the military,” said retired Lt. Gen. David Barno, who led U.S. troops in Afghanistan and is now a professor at American University.

Others interpreted Mattis’s response as an expression of respect for the oath that transgender troops took to serve.

During his confirmation hearings in January, Mattis offered unflinching support for the service of gay and transgender troops. “Frankly, I’ve never cared much about two consenting adults and who they go to bed with,” he said in response to a question from Sen. Kirsten Gillibrand (D-N.Y.).

Even his unscripted remarks to troops in Jordan, which were interpreted by many as a direct rebuke of Trump’s response to the violence in Charlottesville, echoed an alarm Mattis has previously sounded.

This spring, Mattis was asked in a rare interview with New Yorker magazine about his biggest worries in his new job. “The lack of political unity in America,” Mattis replied. “The lack of fundamental friendliness.”

He sounded a similar theme in a commencement speech at the U.S. Military Academy at West Point, N.Y. “For those privileged to wear the cloth of our nation, to serve in the United States Army, you stand the ramparts, unapologetic, apolitical, defending our experiment in self-governance — and you hold the line,” he told the graduates.

Mattis’s public worries about the state of political debate in the United States and the climate of divisiveness reflect a long-standing concern of the military. Political infighting has stymied efforts to produce a long-term budget plan for the Pentagon that Democrats and Republicans have described as essential.

“It’s in­cred­ibly frustrating to the military that we can’t put aside our political differences for the greater good of the country,” said Kathleen H. Hicks, a top Pentagon official in the Obama administration. “They don’t understand it.”

In Mattis’s recent call for the military to “hold the line” until the country comes to its senses, Hicks heard a common refrain. “It’s what they all say to each other to pep themselves up,” she said of the military brass.

Other analysts heard in the statement something darker — a fundamental disconnect between the tight-lipped Pentagon chief and his president.

“I think Mattis is a profoundly decent guy working for a profoundly indecent guy,” said Eliot Cohen, a top official in the George W. Bush administration. “That sets up a conflict. . . . The psychic tension has to be acute.”