Kevin Lamarque / Reuters

White House Chief of Staff John Kelly, who served as Donald Trump’s top adviser for more than a year but repeatedly clashed with the president, will leave the administration “toward the end of the year,” Trump said on Saturday at the White House.

Kelly’s departure comes amid reports that the two men were no longer speaking to each other, and that Special Counsel Robert Mueller has interviewed Kelly. Trump called him “a great guy” and said that he’d announce a successor within days. Politico reported Friday that he had already offered the job to Nick Ayers, who fills the same role for Vice President Pence.

Kelly leaves behind a flawed legacy. The good news: Under his guidance, the White House functioned more effectively than it had during the brief, unhappy tenure of his predecessor, Reince Priebus. The bad news: It remained unfathomably chaotic.

From the point Kelly was installed as chief of staff, following a dramatic bloodletting at the end of July 2017, he managed to bring a greater sense of order to the White House, and to stanch the flood of damaging, leaked stories that characterized the first months of the Trump administration, turning it into more of an irregular flow.

Yet Kelly’s tenure also saw Trump’s galling flip-flop about a white-supremacist march in Charlottesville, Virginia; a White House feud with a Gold Star widow; the bungling of domestic-abuse allegations against then–Staff Secretary Rob Porter; the Helsinki debacle; and several other lowlights.

Kelly, a retired four-star Marine general, was one of several ex-military men who joined the administration early on, initially as secretary of homeland security. But when Priebus was forced out of office as part of a civil war inside the White House, Kelly was drafted to take over its internal operations.

The initial read on Kelly was that he might be able to bring some discipline to a West Wing that had struggled at nearly everything except backstabbing. With his no-nonsense demeanor and military résumé, Kelly was portrayed as the anti-Trump.

Matters got off to a rough start with the march in Charlottesville, where one woman was killed. The president waffled, first decrying violence “on many sides,” then walking that back, then walking back the walk-back in a bizarre press conference. But in the aftermath, Kelly was able to force out the strategist Steve Bannon, who was a major source of infighting as well as press leaks.

The essential moment for understanding Kelly came in October 2017. After several American soldiers were killed in a raid in Niger, Trump used the occasion to attack former President Barack Obama’s handling of condolence letters for slain service members. Trump cited the combat death of Kelly’s own son, an event the retired general had avoided discussing publicly. Some pundits expected Kelly to rebuke Trump. Instead, Kelly staunchly defended him. He also attacked Representative Frederica Wilson, who had provided a damning account of Trump’s phone call to Myeisha Johnson, the widow of slain Sergeant La David Johnson. When video evidence debunked Kelly’s attack on Wilson, the White House said that it was inappropriate to question the chief of staff, because he is a veteran. A few days later, Kelly offered a historically illiterate and politically charged defense of Robert E. Lee on Fox News.

The episode also showed that the gulf between Kelly and Trump wasn’t as large as many analysts had assumed. Kelly was always a Trumpist in ideology—reflexively nostalgic for the past, committed to old-fashioned gender roles, skeptical of cultural change, and strongly anti-immigration. The difference between the men was largely about style and approach, not substance.

Kelly’s stewardship followed, loosely, the template set by James Baker, the acknowledged greatest White House chief of staff, who served under Ronald Reagan and George H. W. Bush. Kelly worked to control the flow of both paper and people to the Oval Office, seeking to reduce the access of advisers who offered Trump bad information, got him riled up, or simply distracted him from his work.

The low point of Kelly’s tenure came in February 2018, with the revelation of accusations of physical and verbal abuse against Porter by two ex-wives. Porter, a veteran Senate staffer, had become an important part of Kelly’s mechanism for controlling the flow of paper to the president—Porter was often by the president’s side, and reportedly touched every piece of paper that made it to Trump. But he was operating on an interim security clearance: His permanent clearance was hung up thanks to the accusations of abuse.

Kelly initially defended Porter, saying he was “a man of true integrity and honor and I can’t say enough good things about him.” After The Intercept published photos showing a black eye that Colbie Holderness said Porter gave her, he resigned. Staffers complained to The New York Times that Kelly was not telling the truth about the events that led up to Porter’s resignation. Meanwhile, other reporting showed that notwithstanding Kelly’s initial statement, he had been informed of the abuse allegations long before they became public.

As I wrote at the time, the Porter episode was often treated as an example of chaos at the White House, but in reality what it showed was the duplicity of many in the West Wing, including the chief of staff. Kelly also had a penchant for impolitic comments, including repeatedly saying that immigrants who had not registered for the Deferred Action for Childhood Arrivals program were “too lazy to get off their asses.”

Dishonest or offensive statements do not, needless to say, disqualify anyone from serving in the Trump administration. But Kelly struggled to assert control of the West Wing. While the Baker strategy had worked for Leon Panetta during the Clinton administration, Trump was unwilling to be corralled. No matter how effective Kelly was as a gatekeeper to the Oval Office, Trump would head to the White House residence and call friends or watch hours of television, both of which could easily derail him. In one notable incident, Trump came out on Twitter against a bill the White House backed, only to reverse course later that morning.

Kelly was occasionally able to twist Trump’s arm. In January 2018, according to The New York Times, the Senate Democratic leader Chuck Schumer left the White House believing he had struck a deal with Trump to extend DACA, only to receive a phone call from Kelly, who thought the deal too weak, spiking it.

Kelly became frustrated with Trump, threatening to quit repeatedly, according to the Times. In Fear, the journalist Bob Woodward quoted Kelly telling other aides in a meeting, “He’s an idiot. It’s pointless to try to convince him of anything. He's gone off the rails. We’re in crazytown. I don’t even know why any of us are here. This is the worst job I’ve ever had.” Kelly denied making the remark, but the feeling appeared mutual: Occasional stories appeared in the press about Trump’s dissatisfaction with his chief of staff or his intention to operate the White House without a chief of staff.

Against that backdrop, the length of Kelly’s tenure in the job was surprising. Whatever his term lacked in quality, it made up for in quantity. By the summer of 2018, Kelly’s departure was widely viewed as coming to an end, despite a Wall Street Journal report saying he’d agreed to stay through 2020.

Then came the maelstrom of Woodward’s Fear and a stunning op-ed in the Times, written by “a senior official in the Trump administration,” which claimed that “many of the senior officials in his own administration are working diligently from within to frustrate parts of his agenda and his worst inclinations.” Together, they laid bare the disrespect that Kelly held for Trump and the continued dysfunction inside the administration.

Somehow, Kelly remained in the job for months after that, weathering several fresh crises. He clashed with the president over Kirstjen Nielsen, his protégé and successor as secretary of homeland security, who Trump believed didn’t take a hard enough line on border security. Kelly also issued a peculiar order purporting to allow troops on the border to use force, which many legal observers said was not within the power of the chief of staff or even the president.

Kelly detests the press, so it’s not often that his voice is heard directly, but people around Kelly tended to explain his decision to work for Trump as a continuation of the duty to serve that had inspired his military service. As a Marine officer, Kelly thrived, repeatedly earning promotions and burnishing his reputation. In the Trump White House, however, Kelly finally encountered a job beyond even his abilities, and one that tarnished his good name as well. It was one battle too many for the old general.

We want to hear what you think about this article. Submit a letter to the editor or write to letters@theatlantic.com.