The Justice Department moved Thursday to drop charges against President Trump’s former national security adviser Michael Flynn, a stunning reversal that prompted fresh accusations from law enforcement officials and Democrats that the criminal justice system was caving to political pressure from the administration.

The unraveling of Flynn’s guilty plea for lying to the FBI came after senior political appointees in the Justice Department determined lower-level prosecutors and agents erred egregiously in the course of special counsel Robert S. Mueller III’s investigation of Russian interference in the 2016 election.

In court documents filed Thursday, the Justice Department said that “after a considered review of all the facts and circumstances of this case, including newly discovered and disclosed information . . . the government has concluded that [Flynn’s interview by the FBI in January 2017] was untethered to, and unjustified by, the FBI’s counterintelligence investigation into Mr. Flynn,” and that it was “conducted without any legitimate investigative basis.”

The Justice Department’s abandonment of the Flynn case is a political windfall for Trump, who had already declared that he was considering a pardon for his former adviser. The Justice Department’s decision means he won’t have to become personally involved in the Flynn case.

Trump forced out Flynn in February 2017, and when he pleaded guilty, the president tweeted: “I had to fire General Flynn because he lied to the Vice President and the FBI. He has pled guilty to those lies. It is a shame because his actions during the transition were lawful. There was nothing to hide!”

On Thursday, Trump told reporters that Flynn was “an even greater warrior” and called the senior FBI and Justice Department officials who pursued him “human scum.” The president’s lawyer, Jay Sekulow, said Mueller “should be ashamed of the conduct of his agents and lawyers that he allowed.”

Through a representative, Mueller declined to comment. A Justice Department spokeswoman said the department did not brief the White House on the decision to move to dismiss the case.

It is highly unusual for the Justice Department to seek to undo a guilty plea, and comes just months after Attorney General William P. Barr pressed prosecutors in another of Mueller’s cases to soften their sentencing recommendation for the president’s friend and former political adviser Roger Stone.

“Attorney General Barr’s politicization of justice knows no bounds,” said House Speaker Nancy Pelosi (D-Calif.). “Overruling the Special Counsel is without precedent and without respect for the rule of law.”

Shortly before the Justice Department abandoned Flynn’s prosecution, the line prosecutor on the case, Brandon Van Grack, formally withdrew — just as the Stone prosecutors had.

In the new filing, Timothy Shea, the U.S. attorney for the District of Columbia, wrote that “continued prosecution of this case would not serve the interests of justice,” but current and former law enforcement officials said the decision was a betrayal of long-standing Justice Department principles. Shea, who was tapped by Barr to lead the U.S. attorney’s office, was the only lawyer to sign the filing; no career attorneys affixed their names to it.

“Another pillar in the foundation of the Department of Justice and the rule of law has fallen,” said one federal prosecutor, who spoke on the condition of anonymity because that person was not authorized to discuss the case publicly. “The justification for this move is not credible, and it may be used by criminals in the future to escape legitimate prosecution.”

Gregory A. Brower, a former U.S. attorney and former senior FBI official, said the move shows Barr is intent on overturning much of the work done by former FBI director James B. Comey, a longtime target of the president’s wrath.

Flynn’s defense team “came up with this idea that, it doesn’t really matter what happened,” said Brower. “The truth here is — and this is from the defendant himself — that he did in fact lie to the FBI about a very serious matter.”

Flynn was one of the first and highest-ranking Trump aides to plead guilty and cooperate with Mueller’s investigation. He pleaded guilty in December 2017 to making false statements about his contacts with Russia’s ambassador to the United States before Trump had taken office and as the FBI was attempting to ascertain whether anyone in Trump’s campaign had coordinated with Russia to influence the election’s outcome.

After Mueller’s probe ended in March 2019, Flynn changed course, hired new lawyers and began fighting to undo his plea deal. The retired general sought to void his conviction by arguing that he was the victim of a partisan conspiracy by prosecutors, federal investigators and even his initial attorneys. His new defense team also alleged he was insufficiently represented by one of Washington’s most prominent law firms, Covington & Burling, when he entered his guilty plea.

Barr in January directed U.S. Attorney Jeff Jensen of St. Louis to review the case’s handling by the federal prosecutor’s office in Washington, which took over Mueller cases last year. Jensen made the final recommendation.

“Through the course of my review of General Flynn’s case, I concluded the proper and just course was to dismiss the case,” Jensen said in a statement. “I briefed Attorney General Barr on my findings, advised him on these conclusions, and he agreed.”

In an interview Thursday on CBS News, Barr said the Justice Department was duty-bound to dismiss the case because prosecutors could not establish a crime had been committed.

“People sometimes plead to things that turn out not to be crimes,” he said.

He disputed the implication that he was doing Trump’s bidding — “No, I’m doing the law’s bidding,” he retorted — and said he was ready to take criticism for the decision.

“I’m prepared for that, but I also think it’s sad that nowadays these partisan feelings are so strong that people have lost any sense of justice,” Barr said.

Thursday’s filing blames a handful of former senior FBI officials for what Shea declared was an unjustified pursuit of Flynn. The filing mentions internal communications between the FBI’s former deputy director, Andrew McCabe, his close aide Lisa Page, and former case agent Peter Strzok — all of whom have faced criticism for other conduct — and argues that those conversations show the FBI investigation of Flynn, dubbed Operation Razor, should not have existed at all.

“The frail and shifting justifications for its ongoing probe of Mr. Flynn, as well as the irregular procedure that preceded his interview, suggests that the FBI was eager to interview Mr. Flynn irrespective of any underlying investigation,” the filing contends.

The filing asserts that the government could not prove Flynn lied, but more important, cannot show his statements were relevant to an ongoing investigation because the FBI was winding down its case against Flynn before suddenly deciding to interview him about his phone calls. Legal analysts and those involved in the case vigorously dispute both assertions.

In a statement, the FBI said that it has cooperated fully with the review of Flynn’s case, and that FBI Director Christopher A. Wray “remains firmly committed to addressing the failures under prior FBI leadership while maintaining the foundational principles of rigor, objectivity, accountability, and ownership in fulfilling the Bureau’s mission to protect the American people and defend the Constitution.”

Comey, now an outspoken critic of Trump, tweeted that the Justice Department “has lost its way. But, career people: please stay because America needs you. The country is hungry for honest, competent leadership.”

In a lengthy statement, McCabe defended the FBI’s actions and said the development “has nothing to do with the facts or the law — it is pure politics designed to please the president.”

Aitan Goelman, a lawyer for Strzok, said the idea that the FBI did not have a good reason to conduct a counterintelligence investigation “is preposterous.”

The filing came one day before a court-mandated deadline for the Justice Department to answer defense allegations of misconduct prompted by the Barr-ordered review. The government’s motion to dismiss the case must be reviewed by a judge, who could press the government for a further explanation.

Flynn, 61, was a senior Trump campaign foreign policy aide who went on to serve 24 days as national security adviser, the shortest tenure on record. He was forced to resign from the White House in 2017 for misstating the nature of his contacts with then-Russian Ambassador Sergey Kislyak to Vice President Pence, senior White House aides, federal investigators and the news media.

In his plea, Flynn admitted he was in touch with senior Trump transition officials before and after his communications with Kislyak. The pre-inauguration communications with Kislyak involved efforts to blunt Obama administration policy decisions on sanctions on Russia and a United Nations resolution on Israel, according to his plea. He also admitted misstating his lobbying work for the government of Turkey.

The move to withdraw charges against Flynn came as new details emerged about his efforts to conceal the nature of his conversations with Kislyak.

White House adviser Hope Hicks testified to House investigators in 2018 that Flynn had sought to enlist her and other Trump aides in backing Flynn’s false claims that he had not discussed sanctions with the Russian ambassador.

Hicks said Flynn did so after questions about his Kislyak call were raised in a January 2017 Washington Post op-ed column by David Ignatius, according to a transcript released Thursday by the House Intelligence Committee. Flynn emailed Hicks, his then-deputy K.T. McFarland and others saying the Ignatius report “is not accurate, what can be done?” Hicks testified.

“I didn’t know that it was a lie at the time,” Hicks said, “but I think, based on the reporting that we’ve seen since then, it would appear that he was not being truthful.”

Flynn faced up to a five-year prison term under the charge, but in exchange for his cooperation with investigators eyeing the Trump campaign, Mueller’s team initially recommended probation as a possible sentence.

Once Mueller’s probe ended, however, Flynn changed course and accused the FBI and prosecutors of manufacturing the case against him.

U.S. District Judge Emmet G. Sullivan rejected those arguments, but Flynn still sought to take back his plea.

Prosecutors have previously rejected any government misconduct in his case. They argued his allegations had no relevance to the sole charge to which he pleaded guilty, and the main focus of that charge, lying about his Kislyak contacts.

In recent days, Flynn had elevated attacks on law enforcement, citing newly unsealed documents turned over by Jensen’s review to the defense showing that the FBI was about to close the investigation into Flynn in early 2017 until new evidence prompted them to keep it open.

Flynn also seized on notes turned over in the review showing that FBI officials discussed in advance how to handle the January 2017 interview with Flynn about his contacts with Russia’s ambassador to the United States before Trump took office.

A page of handwritten notes show that before the Flynn interview, FBI officials discussed the possibility that he would lie to them, given that he had already apparently denied to other White House officials that he had discussed sanctions against Russia weeks earlier in phone calls with Kislyak.

“What is our goal?” the notes said. People familiar with the case said the notes were written by E.W. Priestap, the FBI’s former assistant director for counterintelligence. “Truth/admission or to get him to lie, so we can prosecute him or get him fired?”

Priestap also wrote that the FBI should “protect our institution by not playing games.”

As conservatives seized on those notes last week as evidence that Flynn was railroaded, Trump cranked up his public support for Flynn, calling him a war hero and saying he would consider rehiring him.

Flynn had admitted that he knowingly lied to the Justice Department in foreign lobbying disclosure filings about whether he and his former business partner, Bijan Rafiekian, had acted as agents for the Turkish government, but his new, more aggressive defense blamed that on shoddy work by his past lawyers.

The Jensen review came after Barr named Shea, a top aide to the attorney general, to serve as the U.S. attorney for the District of Columbia, taking charge of both the Flynn and Stone cases.

Shea’s filing Thursday acknowledged that Sullivan previously deemed Flynn’s lies as “material” to the investigation, but argued that he did so “based on the Government’s prior understanding of the nature of the investigation, before new disclosures crystallized the lack of a legitimate investigative basis for the interview of Mr. Flynn.”

Tom Hamburger, Carol D. Leonnig and Felicia Sonmez contributed to this report.