Martin Shkreli just kept talking to reporters and yakking on social media during his fraud trial, despite the efforts of federal prosecutors and his own defense lawyer to get him to stop.

Shkreli appears to have been livestreaming on YouTube as recently as Tuesday night -- one day after prosecutors requested a gag order. His lawyer said before the trial started that he would prefer Shkreli not livestream during the trial.

Shkreli's lawyer opposed the gag order, arguing he has a First Amendment right to speak. But the gag order request came after Shkreli paid a visit last week to the Brooklyn federal court overflow room, where prosecutors said he repeatedly commented on evidence, and the credibility of testifying witnesses, to members of the press.

During his brief visit to the overflow room, Shkreli reportedly said that he was being blamed for everything and lambasted the prosecution, calling them the "junior varsity." His lawyer later said he convinced Shkreli to leave the overflow room "immediately" once he learned he was there.

Judge Kiyo Matsumoto declined the prosecution's gag order request on Wednesday, though Shkreli did pledge not to discuss the case in or around the courthouse. She also said she was "shocked" by the comments Shkreli made to the press and told lawyer Ben Brafman it could affect his ability to defend his client.

CNNMoney reached Shkreli via email on Wednesday morning before the judge ruled on the gag order, but he wouldn't address why he was continuing to ignore the advice of his lawyer -- or the efforts of the prosecutors to silence him.

Shkreli became famous in 2015 when, as the CEO of pharma company Turing, he hiked the price of the life-saving AIDS drug Daraprim by more than 5,000%, to $750 a pill from $13.50.

But that has nothing to do with his fraud case. Later that year he was charged with eight counts, including securities fraud and wire fraud, for allegedly mismanaging money at his investment funds Elea Capital, MSMB Capital and MSMB Healthcare, and also while he was CEO of Retrophin (RTRX). He is accused of lying to investors about his disastrous financial performance to lure funds from them, in what prosecutors have described as a Ponzi scheme.

The Daraprim debacle sparked public outrage and Shkreli became known as "the most hated man in America," which contributed to the court's difficulty in selecting an impartial pool. Shkreli, who could face up to 20 years in prison if convicted, has pleaded not guilty.

In Brafman's response to the gag order request, he described Shkreli as a man who "is under enormous pressure that is compounded by his clearly frail emotional state." He added that "Mr. Shkreli's comments were not intended to disrupt the proceedings. Rather they are defensive measures taken by him in response to what he perceives to be a highly prejudicial one-sided coverage of his trial."

As for paying a visit to the reporters at the courtroom, Brafman said he convinced Shkreli to leave the overflow room. "We have spoken to Mr. Shkreli and we will make every effort to remove this issue from the case," Brafman added in the document.

Related: Shkreli investor testifies: 'I trusted Martin'

The lawyer has made references to Shkreli's mental state previously. "Maybe he's nuts, but that doesn't make him guilty," Brafman said in opening statements last week. He also pointed out in court that Shkreli's victims eventually made money, arguing that means they're not really victims.

Brafman declined to comment to CNNMoney on Wednesday, though he told CNNMoney before the trial started last month that he "would prefer that Mr. Shkreli not livestream during trial."

Shkreli has spent a fair amount of time online, live-streaming his life on YouTube. He sometimes plays guitar, chess, and even lies in bed. At times, there are even long stretches where he does nothing.

"While I can control his conduct in the courtroom, I cannot control his life nor do I have the right to interfere with his personal life," said Brafman in an email on June 23.

Jim Lundy, a defense lawyer for Drinker Biddle & Reath who formerly worked as counsel for the Securities and Exchange Commission and is not involved in the Shkreli case, told CNNMoney "it's typically not a good strategy to anger [the judge] during a criminal trial, and Shkreli is clearly at great risk of doing that. If he's found guilty, the judge is the one who hands down the sentence."

Related: Shkreli's lawyer says 'he's nuts but that doesn't make him guilty'

The prosecutors' gag order request said Shkreli was apparently tweeting under the moniker @BLMBro, where he was "commenting on the evidence presented at trial." This account has since been suspended by Twitter, though a spokesman for the company wouldn't say why.

"We don't comment on individual accounts for privacy and security reasons," said Twitter spokesman Ian Plunkett.

Twitter also apparently suspended another of his accounts earlier this year for making bizarre, unwanted advances to a freelance writer for Teen Vogue. On Twitter, he publicly admired the woman, and even asked her to the inauguration.

Her reply: "I'd rather eat my own organs."