A federal judge on Tuesday postponed the sentencing for Michael Flynn after he lambasted President Trump’s former national security adviser for trying to undermine the country and warned he might not spare Flynn from prison.

The stunning development means that special counsel Robert S. Mueller III’s engagement with Flynn will continue for some months, leaving Flynn to wonder whether he will lose his freedom. Flynn’s attorney requested the delay after the judge’s opinion became apparent, hoping further cooperation with law enforcement would earn the court’s mercy.

From the start, U.S. District Judge Emmet G. Sullivan made clear he was infuriated by Flynn’s conduct — both in lying to the FBI while in the White House and in working to advance the interests of the Turkish government while he was a part of Trump’s campaign.

The judge seemed to take particular umbrage at the suggestion made by Flynn and his supporters, just before the sentencing, that he had been duped by the FBI. Early in the hearing, Sullivan forced Flynn to admit publicly that he knew lying to the bureau was illegal and that he was guilty of a crime. Later, the judge pointed to an American flag in his D.C. courtroom as he berated the former three-star general for his misdeeds.

“Arguably, that undermines everything this flag over here stands for,” the judge said. “Arguably, you sold your country out.”

Flynn, standing straight and flanked by attorneys, looked shaken, his jaw clenched.

Flynn pleaded guilty in Mueller’s probe of Russian interference in the 2016 election more than a year ago, admitting that he lied to the FBI about conversations with Russia’s ambassador to the United States and that he misrepresented in Justice Department documents his work to advance the interests of the Turkish government. He has since been assisting with at least three investigations — including Mueller’s — and his attorneys and the special counsel argued he should get no prison time based on his cooperation.

That now is far from a certainty.

Sullivan opened the hearing Tuesday by taking aim at the suggestion in a pre-sentence filing by Flynn’s attorneys that their client might have been fooled into lying to the FBI. Flynn’s supporters have advanced the notion in recent months that the FBI should have approached Flynn more formally and that he should have been warned in advance that lying to federal agents is a crime.

Even after the hearing, White House press secretary Sarah Sanders said the FBI had “ambushed” Flynn.

The special counsel’s office had earlier rejected the allegation. “Nothing about the way the interview was arranged or conducted caused the defendant to make false statements to the FBI,” prosecutors wrote. Sullivan seemed to take up their case.

The judge reminded Flynn he could get into “more trouble” if he were to lie in court, then asked, “Were you not aware that lying to FBI investigators was a federal crime?”

“I was aware,” Flynn said.

Sullivan asked if Flynn wanted to postpone the sentencing or reconsider his plea.

“I would like to proceed, your honor,” Flynn said.

“Because you are guilty of this offense?” Sullivan responded.

“Yes, your honor,” Flynn said.

His lawyer, Robert Kelner, later took responsibility for the suggestion in the court filing.

That Flynn would want to proceed is no surprise. A day earlier, the special counsel’s office had filed with Sullivan the FBI notes of the interview with Flynn — which reinforced the notion that he lied.

The documents showed Flynn claimed he was unaware of Obama-era sanctions announced as punishment for Russia’s interference in the 2016 election because he had been on vacation in the Dominican Republic and did not have access to television news. In fact, Flynn had called a senior transition official at Trump’s Florida resort, Mar-a-Lago, to discuss what he should say to Russia’s ambassador about the sanctions, and he followed up later to report the upshot of the conversation with the ambassador, according to his plea agreement.

The lies — which prosecutors said Flynn repeated to Vice President Pence and The Washington Post, among others — ultimately cost Flynn his job as national security adviser. Flynn said as a part of his plea that in talking to the ambassador, he was acting in consultation with senior Trump transition officials, including Trump’s son-in-law, Jared Kushner. No evidence has publicly emerged, however, indicating that they told him to lie to investigators.

If Flynn had tried to withdraw his guilty plea, the special counsel’s office might have been able to bring new charges, or at least take back its recommendation that he face no prison time because he had cooperated and accepted responsibility. But even as Flynn reconfirmed his admission of guilt, Sullivan gave no quarter.

At one point, the judge accused Flynn of acting as “an unregistered agent of a foreign country, while serving as the national security adviser to the president of the United States.” The judge later walked back that allegation, because Flynn did work to benefit Turkey when he was on the Trump campaign, rather than when he was in the Trump government.

At another point, Sullivan asked a prosecutor with the special counsel’s office whether Flynn could be charged with “treason” — though he cautioned later that spectators should not read too much into his questioning.

The judge said he would take into account Flynn’s cooperation, but he also detailed Flynn’s crimes.

“I’m not hiding my disgust, my disdain, for this criminal offense,” Sullivan said.

He issued Flynn a warning and asked if he might like to postpone the sentencing so he could keep cooperating with the special counsel’s office.

“I cannot assure you, if you proceed today, you will not receive a sentence of incarceration,” Sullivan said.

Before the proceeding began, Trump had tweeted to wish Flynn “good luck today in court.”

“Will be interesting to see what he has to say, despite tremendous pressure being put on him, about Russian Collusion in our great and, obviously, highly successful political campaign,” Trump wrote. “There was no Collusion!”

For its part, the special counsel’s office stood by its recommendation that Flynn should face a sentence at the low end of federal sentencing guidelines, which called for him to spend zero to six months in prison. But they seemed to offer a less than full-throated defense of Flynn.

When the judge asked if Flynn could be charged with treason, special counsel prosecutor Brandon Van Grack responded, “It’s such a serious question, I’m hesitant to answer it.” He clarified later that the government had “no reason to believe that the defendant committed treason . . . and no concerns with respect to the issue of treason.”

When the judge asked if Flynn was still cooperating with the government, Van Grack answered, “It remains a possibility.”

Kelner ultimately asked for the postponement so Flynn could be “eke out the last modicum” of consideration. Sullivan asked for a status report in 90 days, though he said he was “not making any promises” that he would view the matter differently then.

Kelner reiterated that Flynn had cooperated extensively, asserting that he had “held nothing back.”

“He did understand that, as a three-star general and a former national security adviser, what he did was going to be very consequential for the special counsel’s investigation and very consequential for the nation,” Kelner said. “And then he made the decision publicly and clearly and completely and utterly to cooperate with this investigation, knowing that, because of his high rank, that was going to send a signal to every other potential cooperator and witness in this investigation.”

It is not clear what else Flynn might be able to offer to the special counsel’s office or other investigations. Van Grack, of the special counsel’s office, said the government moved to sentence Flynn now because “the vast majority” of his cooperation was complete.

On Monday, prosecutors in the Eastern District of Virginia charged two of Flynn’s associates with acting as agents of a foreign government and detailed how the trio had worked during the heart of Trump’s campaign to persuade the United States to expel a rival of Turkish President Recep Tayyip Erdogan. Kelner said he believed that case was “the only area in which there is anything left to give.”

Van Grack said in court Tuesday that Flynn assisted — and could have been charged — in the matter.

“The defendant provided substantial assistance to the attorneys in the Eastern District of Virginia in obtaining that charging document,” Van Grack said.

Flynn left the courthouse to protesters’ chants of “lock him up!” Hours after the hearing ended, the judge restricted his travel to within 50 miles of Washington unless he gets special permission.

John Wagner and Philip Rucker contributed to this report.