President Donald Trump’s decision to withdraw America from the Iran nuclear deal shows that there are limits to Defense Secretary Jim Mattis’s influence.

Mattis, the last so-called “adult in the room” who would restrain Trump’s worst foreign policy impulses, spent the past year advocating for the US to stay in the Iran deal. But he finally lost on Tuesday when the president followed through on his campaign promise to rip up the agreement.

That was probably inevitable. Mattis was once flanked by former Secretary of State Rex Tillerson and former National Security Adviser H.R. McMaster, who both agreed with the defense chief on the importance of staying in the Iran deal. But Trump replaced them this year with Mike Pompeo and John Bolton, respectively, who separately noted they wanted to scrap the nuclear agreement — isolating Mattis on one of the most important foreign policy decisions of Trump’s presidency.

The Washington Post reported Tuesday night that Trump previously decided to keep the US in the Iran deal in part because of the advice of his Cabinet. This time, most of his key national security advisers were giving him very different advice.

“Unlike in October, Trump’s Cabinet put up little resistance to a decision many viewed as a fait accompli,” John Hudson and Philip Rucker report. “Mattis, perhaps realizing he was outnumbered after the ouster of Tillerson, refrained from aggressively rehashing his earlier opposition.”

Mattis then toed the line on Wednesday, telling the Senate Appropriations Subcommittee on Defense why it was a good idea for the US to leave the Iran deal.

“We have walked away from the JCPOA because we found it was inadequate for the long-term effort,” Mattis said, using the acronym for the Iran deal’s official name. “We will continue to work alongside our allies and partners to ensure that Iran can never acquire a nuclear weapon.”

Secretary of Defense James Mattis on withdrawal from Iran nuclear deal: "We will continue to work alongside our allies and partners to ensure that Iran can never acquire a nuclear weapon." https://t.co/adJVTimk5J pic.twitter.com/2CaU3AyIR5 — ABC News (@ABC) May 9, 2018

That’s a big change from what he’s said in the past. “Absent indications to the contrary, [the Iran deal] is something that the president should consider staying with,” Mattis told the Senate Armed Services Committee last October.

The question now is if Mattis — who promotes a diplomacy-first approach toward North Korea — can stay in Trump’s good graces ahead of the president’s summit with Kim Jong Un.

Alexandra Bell, a nuclear expert at the Center for Arms Control and Non-Proliferation, told me Trump may not be receptive to Mattis’s counsel. “I think President Trump’s decision to abandon the Iran deal seems to demonstrate that no amount of reason or facts will change his mind once he has decided on a course of action,” she said.

So ahead of Trump’s next biggest foreign policy decision — how, or if, to strike a nuclear bargain with Kim — the defense secretary seems more marginalized than ever before.

“There’s a war of attrition going on for key issues,” Mieke Eoyang, a national security expert at the centrist Third Way think tank, told me, “and it’s not clear when Mattis is winning.”

The Pentagon’s lone survivor

Trump and Mattis seemingly have a good relationship, though it’s not clear why.

Take the fact that they disagree on a stunningly large number of major issues. Last year, Trump reportedly spent weeks asking Mattis to impose a ban on transgender members of the military, which would block transgender civilians from enlisting and reverse an Obama-era directive that allowed roughly 15,500 trans troops to serve openly. But Mattis ignored Trump and took no action.

That prompted Trump to take matters into his own hands. Last July, he tweeted his order to implement the transgender ban policy. Trump then tasked Mattis and Chief of Staff John Kelly, who then was the secretary of homeland security, to lead a months-long review of the issue. But in February, Mattis reportedly recommended to Trump that he allow trans people in and out of the military to serve. And on February 23, the first openly trans recruit joined the military — all while Trump stayed silent.

But that’s not all. Mattis and Tillerson famously formed a united front to push back against the president on key national security issues, angering Trump along the way, and lost again and again. Beyond the Iran deal, the two secretaries told Trump not to move the US embassy in Israel to Jerusalem or impose tariffs on allies, but the embassy will move this month while Trump inches closer toward a trade war with Europe.

Trump duly fired Tillerson because of those disagreements. Mattis, by contrast, still has his job.

And his past as a general doesn’t explain why Trump still likes him. Kelly is a retired Marine four-star general whom Trump might fire at any moment. McMaster was an active-duty Army three-star general, but Trump let him go.

So here’s what may explain Mattis’s longevity: The secretary never undercuts Trump in public. In effect, Mattis doesn’t aim to make news, which helps keep him off the TV his boss watches so often.

But Trump’s summit with Kim will put Mattis in the spotlight, even though Mattis may not be Trump’s go-to Cabinet member on the issue.

“It is clear that Pompeo has been running the North Korea negotiations process, both at CIA and at State,” says Emma Ashford, a foreign policy expert at the libertarian Cato Institute. “Given the fact that Trump appears to have favored the advice of Pompeo and others like Bolton over Mattis when it comes to the JCPOA, I would expect that to continue.”

That’s a potential problem. Despite Pompeo’s recent rounds of negotiations with North Korea, he has consistently backed a forceful stance against Pyongyang. In February, just months before becoming Trump’s top national security aide, Bolton advocated for “striking North Korea first.” Mattis, meanwhile, reiterated his more cautious approach ahead of the Trump-Kim meeting in front of the Senate on Wednesday.

“We see there is some reason for optimism,” Mattis told lawmakers. “We said all along this was a diplomatically led effort, backed up by military force.”

Mattis just lost to the president’s Pompeo-and-Bolton-led war cabinet on the Iran deal. Whether he can win in the coming North Korea discussions could determine whether the US and North Korea continue on the diplomatic path — or turn back toward war.