A federal judge on Wednesday ordered "pharma bro" Martin Shkreli to keep his mouth shut, barring him from talking publicly and tweeting about his federal securities-fraud trial.

"All your client has to do is stop talking in the courthouse and around the perimeter of the courthouse," U.S. District Judge Kiyo Matsumoto said, according to CNBC.

Prosecutors had asked the judge to step in after Shkreli, 34, derided prosecutors, witnesses and the press in a courtroom full of reporters last week. At one point, he called the U.S. Attorney's Office in the Eastern District of New York "junior varsity," according to accounts of several journalists who were there.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

The controversial businessman also told reporters that he hadn't prepared some of the internal documents that the government was using to try to prove he duped investors. And he mocked a woman who had testified against him, saying she couldn't have been a victim of any crime because she ended up making money, CNBC reported.

"I was shocked that there were these comments, these statements," Matsumoto said Wednesday, according to CNBC. "There's a great risk jurors will be exposed."

In their motion for a gag order, prosecutors said Shkreli's comments were part of his "campaign of disruption" in which he has commented "to the press and on social media," and made "a spectacle of himself and the trial."

They accused Shkreli, who was blocked from Twitter earlier this year after harassing a female journalist, of using an anonymous account — @BLMBro — to riff on the trial. That account appeared to be suspended Wednesday morning, but snarky tweets cited in the gag order motion referenced the trial.

In one tweet, the user criticized a New York Times article about the case. "my lawyers and i made fun of this article," the tweet said in part.

Related: Shkreli’s Trial Not On Drug Prices, But This ‘Ponzi-Like’ Scheme

"If this behavior continues, it is only a matter of time before Shkreli, or a member of the public who is repeating Shkreli's statements, exposes one or more jurors to precisely the sort of extrajudicial evidence or commentary and our system forbids," the prosecutors wrote in their motion.

Shkreli's lawyer, Benjamin Brafman ─ who speculated in his opening statements that his client might be "just nuts" ─ responded to the motion by accusing the media of trying to "bait" his client, whom he claimed was in a "frail emotional state" and struggling to defend himself against "one-sided coverage."

Shkreli became a target of public scorn and outrage after he raised the price of an AIDS drug by more than 5,000 percent. His trial, where he faces eight counts of wire and securities fraud, is not related to that move. It is related to his tenure as portfolio manager of two hedge funds and the founder of pharmaceutical company Retrophin.