WASHINGTON — President Trump’s former national security adviser Michael T. Flynn moved late on Tuesday to withdraw his guilty plea on charges of lying to investigators in the Russia inquiry, accusing prosecutors of “bad faith” and vindictiveness after they asked a judge to sentence him to prison for backing out of a deal to cooperate with them.

The last-ditch request means that more than two years after first pleading guilty and after spending dozens of hours answering the questions of investigators for the special counsel, Mr. Flynn would take his chances at trial if a judge agrees to grant his motion. That would set up a collision course with prosecutors who could decide to bring additional charges against him.

Mr. Flynn, a retired Army lieutenant general and former head of the Defense Intelligence Agency whose case marked a striking downfall, has already pleaded guilty twice to lying to the F.B.I. about conversations with the Russian ambassador to the United States during the presidential transition in late 2016. As part of his agreement with the government, Mr. Flynn also admitted that he violated foreign lobbying laws when he failed to disclose work he had done for Turkey.

After he cooperated extensively with prosecutors in the Russia investigation, they recommended leniency in late 2018. Mr. Flynn even agreed to delay his sentencing at the time to offer further cooperation by testifying against a former business associate in a case in Northern Virginia. But Mr. Flynn grew increasingly antagonistic in recent months and hired combative new lawyers in mid-2019.

Those lawyers had tried to convince a federal judge that the F.B.I. had ambushed him as part of a plot by biased investigators, hoping that the case would be thrown out. But the judge rejected those accusations this month as baseless, and prosecutors reversed their stance, saying Mr. Flynn should be imprisoned.

Because Mr. Flynn has already pleaded guilty twice, he cannot unilaterally withdraw from the plea deal. The federal judge in the case, Emmet G. Sullivan of Federal District Court in the District of Columbia, has to sign off on Mr. Flynn’s request and will most likely give prosecutors a chance to respond and schedule a hearing on the matter.

Mr. Flynn’s gamble raises questions about whether he and his lawyers were making a play for a presidential pardon. Days into his presidency, Mr. Trump dismissed Mr. Flynn after learning he had lied to Vice President Mike Pence and other senior administration officials about his conversations with the Russian ambassador, but he has also said Mr. Flynn was treated badly by investigators.

In a relatively disjointed motion filed on Tuesday, Mr. Flynn’s lawyers try to make the case that their client lived up to his plea agreement, including helping the case against his former business associate Bijan Kian.

At his original sentencing hearing late in 2018, Mr. Flynn reasserted his guilt and acknowledged to prosecutors that he lied about working to influence American officials on behalf of Turkey, though prosecutors charged him only with lying to the F.B.I. as part of the deal to secure his cooperation. But they have made it clear they have evidence to charge him with secretly lobbying for Turkey, crimes that carry a stiffer sentence.

Mr. Kian was himself charged with violating foreign lobbying disclosure laws when he worked with Mr. Flynn. On the eve of Mr. Kian’s trial last year in Virginia, Mr. Flynn changed his story, which was critical of the government’s case. Mr. Kian was convicted, but the judge later threw out the charges, saying prosecutors had failed to make a strong enough case.

Mr. Flynn’s lawyers now say their client made no false statements about his work on behalf of Turkey. They say without evidence that prosecutors “concocted” the false statements and accused them of deceit.

“It is beyond ironic and completely outrageous that the prosecutors have persecuted Mr. Flynn, virtually bankrupted him, and put his entire family through unimaginable stress for years,” his lawyers wrote.

They said Mr. Flynn learned only later about problems with foreign lobbying disclosures submitted to the Justice Department. He has blamed his former lawyers for filing inaccurate forms without his knowledge and accused the government of retaliating against him for hiring new lawyers who refused to let their client lie in Mr. Kian’s trial.

Mr. Flynn’s lawyers were silent on the issue of his acknowledgment in court that he lied to the F.B.I. in the Russia investigation. It is unclear how that squares with his decisions to plead guilty both in 2017 and 2018.

In their recent sentencing memo asking the judge to sentence Mr. Flynn to up to six months in prison, prosecutors said he was no victim.

“Far from accepting the consequences of his unlawful actions, he has sought to blame almost every other person and entity involved in his case, including his former counsel,” they wrote.