Florian Gaertner/Getty

H.R. McMaster went into Donald Trump’s White House an unexpected, out-of-place fit whom his security-field allies hoped would restrain the president. He exits it without an active military career and with his long-cultivated reputation for integrity tarnished by his tumultuous year working for Trump.

And McMaster turns his job over to a right-wing foreign policy expert considered all but bloodthirsty and eager to encourage Trump’s most hawkish instincts—exactly the sort of figure McMaster’s many allies in defense circles feared would rapidly emerge in the wake of McMaster’s departure.

Late Thursday afternoon, Trump finally pushed McMaster out, the culmination of an agonizing few weeks of humiliating leaks that the Army three-star general was a dead man walking.

From the start, McMaster was an accidental national security adviser, hired abruptly after Mike Flynn flamed out and a different senior officer turned Trump down. His Washington—and global—profile was as a straightjacket on a president with whom he shared neither history, experience or temperament.

It was a circumstance bound to make their relationship a test of wills. And it proved to be a painful coda on an extraordinary career that saw McMaster become known as a unicorn of a senior military officer: someone who fought the Army’s instincts, refuted its perceived wisdom, and won. That status, forged in the Iraq war, made McMaster’s subordinate position appear all the more excruciating.

Hours after he was finally dismissed by Trump, McMaster received a tribute from his most important mentor.

“General McMaster has served our country admirably—and selflessly and forthrightly—as President Trump’s national security adviser,” David Petraeus, the retired Army general and former CIA director, told The Daily Beast. It was Petraeus, in 2008, who ensured the Army gave the iconoclastic McMaster his first star.

“He established and oversaw an impressive process for providing options to the president. He helped develop a number of important initiatives for the fight against Islamist extremists, malign Iranian activity, and North Korea’s threatening nuclear and missile programs. And he guided the drafting of a superb National Security Strategy—in less than a year. Again, he has served our country very well.”

McMaster’s successor, John Bolton, is as near a polar opposite as Trump could have found for national security adviser. The former UN ambassador long has had a personal chemistry and rapport with the president in ways McMaster lacked. According to sources close to Trump, the president routinely talks about Bolton even when Bolton isn’t around, and wonders what he would have to say on policy discussions related to North Korea, Iran, and China. Trump administration sources also tell The Daily Beast that in recent days and weeks, a steady cast of the president’s most prominent advisers and allies—including Rep. Mark Meadows and Sen. Tom Cotton (R-AR)—had been talking up the former UN ambassador.

But Bolton was still surprised when he heard he landed the job. The two had discussed it for a while. But the offer was only made once Bolton showed up at the White House on Thursday afternoon. Hours later, Bolton was on Fox News, his new boss’s favorite channel, talking about his new gig.

McMaster spent his White House tenure trying to save the Iran nuclear deal from Trump. Bolton delights in encouraging Trump to rip it up. In the White House meetings the two have had over the past weeks, Bolton has reiterated his position that nuclear deal is not one that can be “fixed” and that withdrawal as soon as possible is the best course of action, according to two people briefed on their conversations.

“H.R. McMaster served our country with honor for over 30 years, none of them more trying or important than the year he served as national security adviser. The nation is far less secure with his departure.”

The only issue where McMaster appears to align with Bolton is on a preventive attack on North Korea, a position that both disappointed McMaster’s allies and which contradicts Trump’s desire to place a more hardline team in place ahead of Trump’s meeting with Kim Jong-un.

“H.R. McMaster served our country with honor for over 30 years, none of them more trying or important than the year he served as national security adviser,” said John Nagl, McMaster’s friend, fellow Army-officer veteran of Iraq and counterinsurgency theorist-practitioner. “The nation is far less secure with his departure.”

Trump, who is loath to fire his subordinates, let McMaster twist in the political wind for weeks. Rumors swirled that General Vincent Brooks might soon leave his command of U.S. forces in Korea, freeing up McMaster for a fourth star and a final, face-saving assignment. Instead, McMaster has opted to retire, raising questions over whether Trump offered him a path to continued service—or if McMaster had had enough. McMaster’s generalship was famously hard-won, coming only on the personal intervention of Petraeus against Army leadership, at the height of Petraeus’ influence.

McMaster’s most lasting policy impact may have doomed his relationship with Trump. McMaster convinced Trump, against the president’s instincts, to escalate the nearly 17-year old war in Afghanistan, a plan that has satisfied few on either the left or the right. The military and diplomatic commitments McMaster prevailed on Trump to undertake will be the hardest policy for Bolton to unravel—should the consistently bellicose Bolton even desire it. While McMaster has presided over the drastic escalation of aerial bombing in Afghanistan, Bolton goes a step further, urging Trump in November to ignore an international war-crimes investigation.

The longer McMaster stayed in the White House, the more his allies on the outside bit their tongues, in the hope that his increasingly vocal Trumpism was the cost of doing Trump-restraining business. McMaster and another now-departed White House aide, Gary Cohn, even wrote a tendentious op-ed purporting to reconcile Trump’s America-first unilateralism with traditional U.S. internationalism. Some took to saying that McMaster’s book Dereliction of Duty, his scathing attack on a docile Johnson-era Joint Chiefs of Staff that acquiesced to the Vietnam disaster instead of standing up to the delusions of the president, was going to need a major new foreword on future editions.

But not even McMaster’s friends, including Nagl, could stomach the general’s decision to defend Trump divulging intelligence provided by Israel on Islamic State to the Russian foreign minister and ambassador in the White House. McMaster, dressed in a business suit but throwing his stars on the table, publicly called the shocking decision “wholly appropriate.” In an NPR interview, a horrified Nagl invoked the West Point Honor Code to say his friend had not been truthful.

Still, Nagl said: “I think literally the fate of the Earth could be in H.R. McMaster’s hands at this point.”

More recently, McMaster reasserted his distance from Trump on Russia. The national-security strategy McMaster constructed treated Russia as an adversary—despite Trump—though its future under Bolton is now in doubt. Last month, McMaster earned himself a rebuke from Trump on Twitter after saying that Russian interference in the 2016 election was “incontrovertible.” Nevertheless, in what now proves to be McMaster’s final speech as Trump’s national security adviser, McMaster blasted Russia as “complicit” in human-rights atrocities in Syria.

Asked what McMaster was likely to do in the next chapter of his life, Nagl told The Daily Beast: Dereliction of Duty II: President Trump and the End of American Leadership.