When I think of Jim Mattis, I will always remember the peppery two-star general I met for the first time in Iraq. It was the summer of 2003, and he had just led the 1st Marine Division on the "march up" to Baghdad. He showed his steely will to win by cashiering on the spot a regimental commander who wasn't moving fast enough for his liking.

Now he was supervising the occupation of southern Iraq from a makeshift headquarters in Babil near the site of the legendary Tower of Babel. While more permanent housing was being erected for the Marines and some newly arrived Polish troops, he was content to sleep in a tent behind his operations center and to stand in line for chow behind ordinary grunts.

I was dazzled by how he conducted his battle update assessments (in civilian-speak!) and his afternoon staff meetings (with a mixture of humor, profanity and erudition). It was as close to a reincarnation of George S. Patton as I would ever meet.

President Donald Trump was apparently just as impressed when he met Mattis after the 2016 election, because he decided to appoint him secretary of defense. But Mattis was to turn out far different from what Trump expected. He had in mind a caricatured image of a militarist named "Mad Dog," a nickname that the cerebral and studious general hated. Before long Trump was calling him "Moderate Dog" and griping, inaccurately, that he was a closet Democrat.

I was not surprised to find that Mattis was a centrist who supported NATO and the Iran nuclear deal while opposing attacks on both Bashar al-Assad and Kim Jong Un. What surprised me is that, having come from the world of "Generation Kill," he could so successfully make the transition to the real-life "House of Cards" in Washington. Prior to his Pentagon appointment, I thought of Mattis as an inspirational battlefield leader who had little patience for paperwork or backroom dealings. His clashes with policymakers when he ran Central Command in the Obama administration reinforced that view.

I was pleasantly surprised to see how skillfully he exerted influence in the halls of power. He kept his distance from the president without alienating him - a delicate balancing act that Secretary of State Rex Tillerson, for one, could not pull off. Mattis helped persuade Trump to affirm NATO's Article 5 mutual-defense guarantee, take some tough steps to check Russian aggression, and expand military commitments in Afghanistan, Iraq and Syria.

We now know how difficult the secretary's job was. Not even a renowned general straight out of Central Casting could keep a mercurial, stubborn and willfully ignorant chief executive in check indefinitely. Just before the midterm elections, Trump dispatched troops to the Texas border in a transparent political stunt. Mattis gritted his teeth but soldiered on so that he could maintain his influence on the issues that mattered most to him.

Having served in both Iraq and Afghanistan, just like Trump’s previous national security adviser, H.R. McMaster, Mattis was passionate about not leaving the region prematurely and thus risking the gains that the men and women under his command had sacrificed so much to achieve. For him, it was an issue of honor — his own and the nation’s.

Trump does not appreciate the deep commitment that troops feel to the causes for which they fight. His only enduring loyalty is to his bank account. One day he claimed that the war against Islamic State had been won; the next, that someone else would now have to fight it. He even had the nerve to suggest that America's war dead would support his bug-out from Syria. How long before he makes a similarly offensive claim about Afghanistan, where he is downsizing the U.S. commitment?

Confronted with a president who disregards the best military advice, Mattis became the highest-ranking official since Secretary of State Cyrus Vance in 1980 to resign in protest. He explained his decision in a blistering letter that offered not a word of praise for the president. Mattis wrote that he could no longer serve because Trump did not agree with him "that our strength as a nation is inextricably linked to the strength of our ... alliances and partnerships" and that "we must be resolute and unambiguous in our approach to those countries whose strategic interests are increasingly in tension with ours." In other words, Mattis doesn't believe in betraying allies such as the Syrian Democratic Forces or the government of Afghanistan while handing over territory to enemies such as Russia, Iran, the Taliban and the Islamic State.

Mattis' resignation was his final act of devotion to a nation he has served his whole adult life. His service has been particularly important at the Pentagon, where he labored to save the world from Trump. He failed, but it was not his fault. No one else could have done any better. Now his departure terrifies the entire world — and for good reason. One of the last remaining adults has left the building. The president is home alone with his Twitter account — and our nuclear arsenal.

Max Boot | The Washington Post

Max Boot, a Washington Post columnist, is the Jeane J. Kirkpatrick senior fellow for national security studies at the Council on Foreign Relations and a global affairs analyst for CNN. He is the author of “The Corrosion of Conservatism: Why I Left the Right."