I met Jim Mattis in Anbar Province, Iraq, in 2004. He was a major general, commanding the First Marine Division in a tough counterinsurgency fight. I was an Army major, serving in a tank battalion that the Army had provided to the Marines to give them extra firepower. On the way to the rehearsal for a sweep-and-clear operation, General Mattis’s ground convoy was ambushed, with at least one of the Marines on his personal protection detail seriously hurt. Generals usually took helicopters, but General Mattis wanted to see the terrain for himself, from a grunt’s perspective, and the talk among the junior officers was of his personal courage in the battle with insurgents that followed the ambush. We were also impressed by the way he improved the operation plan. He had apparently always been full of ideas, and vocal about them, so one of his previous commanders had dubbed him Chaos, short for “Colonel Has Another Outstanding Suggestion.” Nobody called him Mad Dog.I later had the privilege of fighting another battle with General Mattis, who by 2005 was a three-star general leading the Marine Corps’ Combat Development Command, responsible for the thinking side of war. General Mattis worked with David Petraeus, then a three-star general in the Army, in the writing of the Army and Marine Corps’ Counterinsurgency Field Manual, on which I played a junior role. General Mattis, known as the “Warrior Monk,” had a personal library of 7,000 volumes on war and strategy; he gave as good as he got from General Petraeus, who holds a doctorate from Princeton University. The two created a revolutionary manual that changed how the Army and the Marines thought about conflict — and how they fought the wars in Iraq and Afghanistan.After retiring from the Army, I shared an office with a former Marine named Nate Fick who had participated in the invasion of Afghanistan immediately after the attacks of September 11. Nate told me about checking his foxholes at zero-dark-thirty one morning, expecting to see two Marines awake and one sleeping in each hole. He saw three heads up in one of his foxholes, and crawled over to investigate. One belonged to Brigadier General Jim Mattis, the senior Marine commander in southern Afghanistan, who had decided to spend the night checking holes himself. Marines apparently don’t sleep much.General Mattis retired from the Corps in 2013 with four stars and went to work in academia before being recalled to serve as President Trump’s secretary of defense. He gained a reputation as the most independent, and the best, of the president’s cabinet officers, serving as a reassuring bulwark to America’s allies who sometimes questioned the president’s commitment to fighting common enemies. The reputation Mr. Mattis earned for being the “adult in the room” angered the president, and his admirers knew that his days were numbered. Some of us were surprised that he went along with the clearly political deployment of more than 5,000 soldiers to the southern border during the midterm elections, but I believed that Mr. Mattis’ loyalty to his troops, and belief that any secretary of defense who replaced him would be more political, led him to swallow hard and go along with the stunt. It is noteworthy that he went down to the border to visit his troops in their tent city, demonstrating personal leadership that the commander in chief, who has yet to visit American troops in a war zone, has chosen not to emulate.The straw that broke Mr. Mattis’ back was the president’s decision to withdraw all American troops from Syria. He has lived his entire adult life locking arms with America’s friends, risking his life countless times. He could not bear to see the United States abdicate its leadership in the fight against ISIS and Al Qaeda, or abandon the Kurdish fighters who have paid so heavy a price in clearing much of Syria from ISIS fighters. His resignation letter was a ringing endorsement of the lodestar that has guided generations of troops: We will die rather than abandon those who fight by our side against those who would harm our people and way of life. Mr. Mattis believed that the president has a different ethos, and deserves a Secretary of Defense who can support that infinitely lesser credo.I last saw Jim Mattis two weeks ago at the Army-Navy football game. He wasn’t very interested in what was happening on the field, but spent a great deal of time talking to a group of wheelchair-bound veterans — inquiring about their injuries and their treatment, offering his card to those who needed assistance or who just wanted to visit him in the Pentagon. After he had spent significant time with each wounded veteran, he spent a few minutes reminiscing with me about our time together in Anbar Province. It was pretty clear that he would have preferred to be back there, fighting against insurgents and terrorists, rather than engaging in the Washington combat to which he had to return after the game. I thanked him for his continued service, as should we all. America will be less safe, and our enemies greatly heartened, by his departure.John A. Nagl is the headmaster of The Haverford School outside Philadelphia. A retired Army officer who served in both Iraq wars, he is the author of “Knife Fights.”Follow The New York Times Opinion section on Facebook, Twitter (@NYTopinion) and Instagram.