In late January, acting Attorney General Sally Yates delivered a startling message to the Trump administration: National Security Adviser Michael Flynn had lied to other top White House officials about his dealings with the Russian ambassador to the US and was potentially vulnerable to blackmail by the Kremlin.

Now those lies have cost Flynn his job: On Monday night, Flynn resigned amid growing questions about whether he had misled Vice President Mike Pence, and potentially the FBI, about his phone calls with the Russian envoy on December 29, the same day the Obama administration slapped new sanctions on Moscow for its interference in the 2016 presidential elections.

In his resignation letter, Flynn said "the fast pace of events" during the transition meant that he had "inadvertently briefed the Vice President Elect and others with incomplete information regarding my phone calls with the Russian Ambassador." Flynn’s letter didn’t include any further details about his conversations with Sergey Kislyak, the Russian diplomat.

Flynn had long denied discussing sanctions in his call with Kislyak, but US officials had told the Washington Post and New York Times that Flynn explicitly talked about the sanctions and hinted that Trump might be willing to lift them. That kind of conversation could be a violation of an obscure federal law, the Logan Act, which prohibits people outside the executive branch from making foreign policy on behalf of the US administration.

No one has ever been prosecuted under the Logan Act, but Flynn is facing a second and potentially far more dangerous investigation. The FBI is actively probing his interactions with Kislyak, and resigning from his White House post won’t shield Flynn from potential future criminal prosecution.

Until late Monday night, it wasn’t clear if Flynn’s lies would be enough to force Trump’s hand. On Monday afternoon, White House aide Kellyanne Conway told MSNBC that Flynn "does enjoy the full confidence of the president," while CNN’s Jim Acosta reported that Pence and Flynn had buried the hatchet. Shortly after Conway spoke, White House spokesperson Sean Spicer put out a written statement that conspicuously avoiding giving a vote of confidence to Flynn and instead said, ominously, that "the president is evaluating the situation."

Just hours later, Flynn was gone, replaced at least temporarily by retired Gen. Keith Kellogg, who had served as his chief of staff. The Washington Post reported late Monday night that Kellogg was a finalist for the post along with former CIA Director David Petraeus and Vice Adm. Robert Hayward, a former deputy commander of the Pentagon’s Central Command.

It’s not a reassuring sign when an administration that has been in office for less than a month has to replace its national security adviser, a tacit admission that the new president bungled one of his first major personnel choices. Flynn, though, had been particularly ill-suited to his post, with a personality and temperament that magnified many of Trump’s worst flaws.

Derek Chollet, who held a variety of senior posts during the Obama administration, said Flynn had been "off to the roughest start of any national security adviser in history," but cautioned that his firing wouldn’t be enough to fix all that ails the White House.

"Presidents get the national security process that fits their styles," he said. "Given that erraticism and improvisation seem intrinsic to Trump, I expect that to remain the same regardless of who is sitting in the West Wing."

Put another way, Flynn’s ouster could be a temporary boost for a White House adrift. Whether it’s a permanent one depends on the president himself.

Flynn shared many of Trump’s worst flaws. That’s not a good thing for a national security adviser to do.

Flynn had seemed like a dead man walking for a long time.

In the weeks before the Russia scandal, a series of leaks suggested that Defense Secretary Jim Mattis, Secretary of State Rex Tillerson, and CIA Director Mike Pompeo had lost confidence in Flynn and were holding private meetings expressly designed to exclude him. In a move first reported by Politico, the CIA — with Pompeo’s blessing --- blocked a key Flynn aide from receiving the high-level security clearance he needed to work on the National Security Council (NSC).

Staffers on the NSC, meanwhile, had been privately telling reporters that Flynn wasn’t fulfilling one of the most important part of his job: making sure complex national security policy changes moves were vetted with Cabinet members and other key officials before being presented to the president. Other NSC staffers had begun using encrypted communications because of fears that Flynn and his deputies were monitoring their cellphones and emails to find leakers.

Still, Trump didn’t seem to be in any rush to fire a trusted loyalist who had won a place in his inner circle during the campaign by vigorously defending Trump’s national security bona fides and sharply attacking Hillary Clinton. Flynn went so far as to lead crowds of Republicans at the GOP convention in Cleveland in chants of, "Lock her up," shocking many of his former military colleagues. When Flynn got his new post, two retired officers told me in separate interviews that they considered him to be "unhinged."

In part, that’s because of Flynn’s worldview, which closely aligns with some of the most unsettling parts of Trump’s. As my colleague Zack Beauchamp and I have written, Flynn "swims in the same swamp of hyperpartisan, frequently fabricated, and disturbingly anti-Muslim rhetoric" as Trump and the president’s powerful chief strategist, Steve Bannon. Flynn’s tweets include a video that claims "Islam … wants 80 percent of humanity enslaved or exterminated," which he captioned "Fear of Muslims is RATIONAL."

That means Flynn had been amplifying — rather than moderating — Trump’s anti-Muslim leanings, a belief system that helped bring about the controversial executive order temporarily halting all immigration and refugees from seven Muslim-majority nations.

Flynn is believed to have helped fuel Trump’s skepticism about the intelligence community, which he likened to Nazis and publicly mocked for concluding that Russia had tried to interfere in the elections to ensure Trump’s victory.

Flynn was also, if anything, more unsettlingly pro-Putin than his boss, a dynamic that has been visible since the campaign. Flynn has spoken very positively about the prospect of partnering with Putin’s regime to fight terrorism, and repeatedly appeared on Russia’s English-language propaganda outlet, RT. Flynn was so in with RT that he had been paid to give a speech at its 10th anniversary dinner in Moscow — where he sat at the head table with Putin himself.

Flynn’s departure is an opportunity for Trump — if he takes it

Guessing how long Flynn was going to keep his job had become a popular Washington parlor game (my money had, as it turned out correctly, been on him being out by the spring). The next parlor game will be about who replaces him.

Lost in the chaos that has surrounded the first weeks of the Trump administration is that the new president’s national security team is actually quite good. Mattis is beloved inside the Pentagon and on Capitol Hill, while Tillerson has strong support from centrist Republican foreign policy experts like former Defense Secretary Robert Gates and former Secretary of State Condoleezza Rice.

Flynn was widely seen as the weak link, an ideologue willing to go to war with the US intelligence community and to publicly criticize the Pentagon’s top generals. He had a toxic relationship with Mattis and Pompeo, and the New York Times recently reported that Trump himself was souring on Flynn "because of his sometimes overbearing demeanor" and for "presiding over a chaotic and opaque NSC transition process."

Trump now has the chance to reboot the national security side of his floundering administration and replace the divisive Flynn with a more moderate and well-regarded figure capable of working productively with Mattis and other powerful officials. The question, as always, is what the new president will choose to do with it.