A federal judge tore into former national security adviser Michael Flynn during his sentencing hearing on Tuesday by saying he sold out the U.S. while he briefly held his position, although the judge later admitted he was mistakenly levied that charge.

"You were an unregistered agent of a foreign country while serving as the national security adviser to the president," U.S. District Judge Emmet G. Sullivan said during Flynn's sentencing hearing in Washington.

"Arguably, this undermines everything this flag over here stands for. Arguably, you sold your country out."

"In the White House, in the West Wing," the judge said. "By a high-ranking security officer who up to that point had an unblemished career of service to his country. It's a very serious offense."

Sullivan's comments appeared to reference this week's charging of two of Flynn's associates in the Eastern District of Virginia on Monday because of their work for Turkey. Flynn himself, however, was not charged, and when the court reconvened after a recess, the judge admitted he made the charges in error.

"I made a statement about Mr. Flynn acting as a foreign agent while serving in the White House and I may have misspoken,” said Sullivan. “Does that need to be corrected for the record?"

Brandon Van Grack, a prosecutor for special counsel Robert Mueller, answered in the affirmative, and noted that Flynn ended his lobbying efforts in November 2016 before the Trump administration began.

The judge did not explicitly apologize, however.

Before the break, the judge kept pushing by asking Van Grack if Flynn's alleged conduct "rises to the level of treasonous activity."

When Van Grack hesitated to answer, Sullivan asked again: "Could he have been charged with treason?”

"That is not something we were considering in terms of charging the defendant," Van Grack answered.

Sullivan walked those comments back as well after the break, but again did not apologize.

"I was just trying to determine the benefit and the generosity of the government," the judge said. "Don't read too much into the questions I ask."

Van Grack agreed, and said the government “has no reason to believe the defendant committed treason.”

The judge did indicate he was angry about the charge Flynn has accepted, which is lying to the FBI.

"The aggravating circumstances are serious. Not only did you lie to the FBI, you lied to senior officials in the incoming administration," Sullivan said.

Flynn was only charged with lying to the FBI in December 2017 when it was announced he had taken a plea deal with the special counsel. When he was interviewed at the White House in January 2017, Flynn lied to FBI agents about the conversations he had with then-Russian ambassador Sergey Kislyak.

[Read: Newly released Mueller memo details Michael Flynn's lies to the FBI]

Flynn was expected to be sentenced on Tuesday for lying to the FBI, but that sentencing was delayed, as it was revealed Flynn could still cooperate with special counsel Robert Mueller. Van Grack said Flynn gave information to help bring the charges against his two former associates, one who is in custody.

Federal sentencing guidelines have recommended that Flynn serve between zero to six months in jail for the charge. Both Mueller's team and lawyers for Flynn have previously argued in court documents that he should avoid jail time due to his "substantial cooperation."