WASHINGTON – Back when their relationship was fresh and new, and President Donald Trump still called his defense secretary "Mad Dog" — a nickname Jim Mattis detests — the wiry retired Marine general often took a dinner break to eat burgers with his boss in the White House residence.

Mattis brought briefing folders with him, aides said, to help explain the military's shared "ready to fight tonight" strategy with South Korea, and why the North Atlantic Treaty Organization has long been viewed as central to protecting the United States. Using his folksy manner, Mattis talked the president out of ordering torture against terrorism detainees and persuaded him to send thousands more American troops to Afghanistan — all without igniting the public Twitter castigations that have plagued other national security officials.

But the burger dinners have stopped. Interviews with more than a dozen White House, congressional and current and former Defense Department officials over the past six weeks paint a portrait of a president who has soured on his defense secretary, weary of unfavorable comparisons to Mattis as the adult in the room, and increasingly concerned that he is a Democrat at heart.

Nearly all the officials, as well as confidants of Mattis, spoke on condition of anonymity to discuss the internal tensions — in some cases, out of fear of losing their jobs.

In the second year of his presidency, Trump has largely tuned out his national security aides as he feels more confident as commander-in-chief, the officials said. Facing what is likely to be a heated re-election fight once the 2018 midterms are over, aides said Trump was pondering whether he wanted someone running the Pentagon who would be more vocally supportive than Mattis, who is vehemently protective of the U.S. military against perceptions it could be used for political purposes.

White House officials said Mattis had balked at a number of Trump's requests. That included initially slow-walking the president's order to ban transgender troops from the military and refusing a White House demand to stop family members from accompanying troops deploying to South Korea. The Pentagon worried that doing so could have been seen by North Korea as a precursor to war.

Over the past four months alone, the president and the defense chief have found themselves at odds over NATO policy, whether to resume large-scale military exercises with South Korea and, privately, whether Trump's decision to withdraw the United States from the Iran nuclear deal has proved effective.

The arrival at the White House earlier this year of Mira Ricardel, a deputy national security adviser with a history of bad blood with Mattis, has coincided with new assertions from the West Wing that the defense secretary may be asked to leave after the midterms.

Mattis himself is becoming weary, some aides said, of pushing back against what Defense Department officials think are capricious whims of an erratic president.

The defense secretary has been careful to not criticize Trump outright. Pentagon officials said Mattis had bent over backward to appear loyal, only to be contradicted by positions the president later staked out. How much longer Mattis can continue to play the loyal Marine has become an open question in the Pentagon's E Ring, home to the Defense Department's top officials.

'Competence and continuity'

The fate of Mattis is important because he is widely viewed — by foreign allies and adversaries but also by the traditional national security establishment in the United States — as the Cabinet official standing between a mercurial president and global tumult.

"Secretary Mattis is probably one of the most qualified individuals to hold that job," Sen. Jack Reed of Rhode Island, the top Democrat on the Senate Armed Services Committee, said in an interview. His departure from the Pentagon, Reed said, "would, first of all, create a disruption in an area where there has been competence and continuity."

But that very sentiment is part of a narrative the president has come to resent.

The one-two punch last week of the Bob Woodward book that quoted Mattis likening Trump's intellect to that of a "fifth- or sixth-grader," combined with the New York Times Op-Ed by an unnamed senior administration official who criticized the president, has fueled Trump's belief that he wants only like-minded loyalists around him. (Mattis has denied comparing his boss to an elementary school student and said he did not write the Op-Ed.)

Trump, two aides said, wants Mattis to be more like Secretary of State Mike Pompeo, a political supporter of the president. During a televised June 21 Cabinet meeting, held as migrant children were being separated from their parents at the southwestern border, Mattis and Pompeo were a study of contrasts: On the president's left, the defense secretary sat stone-faced; on his right, the secretary of state was chuckling at all of Trump's jokes.

Getting Mattis to abandon the apolitical stand he has clung to his entire life will be next to impossible, his friends and aides said.

"Secretary Mattis lives by a code that is part of his DNA," said Capt. Jeff Davis, who retired last month from the Navy after serving as a spokesman for Mattis since early in the Trump administration. "He is genetically incapable of lying, and genetically incapable of disloyalty."

That means the defense secretary's only recourse is to stay silent, aides to Mattis said. While he does not want to publicly disagree with his boss, he is also uncomfortable with showering false praise on Trump.

But cracks are showing.

In April, John Bolton became the White House national security adviser, replacing Army Lt. Gen. H.R. McMaster, who was long viewed as a subordinate to Mattis because of his rank as a three-star general compared with the retired Marine general's four stars. Bolton is far more hawkish than either Mattis or McMaster.

For instance, Mattis recently resisted White House attempts to closely supervise military operations by demanding details about U.S. troops involved in specific raids in Afghanistan and elsewhere.

One American official said the White House had bypassed the Pentagon by getting classified briefings of coming operations directly from the Special Operations task forces, to the frustration of Mattis.

That may seem a small and insular example of bureaucratic gamesmanship. But administration officials said it illustrates the tensions between Mattis and Trump: Either the defense secretary cannot appeal to the president, or he has and Trump is refusing to back him up.

In contrast with McMaster, Bolton recently began attending regular weekly meetings between Mattis and Pompeo. Pentagon officials complain that White House interference has returned to the level of Susan Rice, who as Obama's national security adviser was accused of micromanaging the department's every move.

For Trump, getting rid of his defense secretary would carry a political cost. Mattis is revered by the men and women of the U.S. military. Most of the rest of his fans are people Trump does not care about: Democrats, establishment Republicans and U.S. allies.

But moderate Republicans — whom Trump will need in 2020 — appear to trust Mattis as well, and firing him could hurt the president with that key group.