A federal judge Wednesday ordered “pharma bro” Martin Shkreli to stop commenting on his ongoing securities fraud trial in and around the public areas of a New York courthouse after Shkreli went on a five-minute rant to reporters last week.

Also Wednesday, prosecutors who sought to have Shkreli gagged from talking about the case revealed that Shkreli’s defense team had several times approached prosecutors about potentially resolving the case with a guilty plea to avoid going to trial.

Prosecutors said that fact, disclosed for the first time in Brooklyn federal court, contradicted Shkreli’s claim to journalists last week that he never considered a plea offer.

An angry Benjamin Brafman, Shkreli’s lead lawyer, said Shkreli “categorically” refused to even consider a plea deal with the prosecution, although Brafman conceded he himself had reached out to prosecutors about a potential deal.

Brafman said Shkreli told him, “I would never plead guilty to something I did not do…. We’re going to trial.”

Brafman said that he was bound ethically to see if the case could be resolved before going to trial to protect the interests of his client.

But, “He told me, ‘I’m not pleading guilty to something did not do,’ ” Brafman said.

Prosecutors, when they filed their gag order motion on Monday night, wrote that they strongly suspected that Shkreli had resumed posting on the social media service Twitter, which had banned him earlier this year after he harassed a female journalist in a series of tweets.

Prosecutors wrote they believed Shkreli was using the new Twitter handle @BLMBro. That account’s tweets did contain comments on the ongoing trial and were written in Shkreli’s often-acerbic style.

Twitter suspended that account after the prosecution’s motion was reported.

In gagging Shkreli, at least in and around court, Judge Kiyo Matsumoto indicated she was deeply troubled by Shkreli having walked into a courtroom occupied by several reporters last week and making comments on the case.

During that short visit, Shkreliblasted prosecutors, witnesses and the press.

Matsumoto said she was afraid that jurors in the trial would end up hearing what Shkreli said if he continued talking; she was particularly concerned that he spoke to reporters while walking out of court last week after his rant.

“All your client has to do is stop talking in the courthouse and around the perimeter of the courthouse,” Matsumoto said.

“There will be no more commenting by Mr. Shkreli,” Brafman told the judge.

Brafman claimed that client suffers from anxiety and was being baited by reporters and their allegedly unfair coverage of the case.

Shkreli is charged with securities fraud in connection with his alleged looting millions of dollars from Retrophin, the publicly traded drug company he founded. Prosecutors claim he used the money to repay investors whom he allegedly defrauded at two hedge funds he had run, in addition to paying off personal debts.

In their motion, prosecutors cited Shkreli’s surprising, impromptu meeting with reporters covering the case last Friday, among other incidents.

During that meeting, Shkreli called the prosecutors “the “junior varsity,” criticized a witness against him, and lambasted headlines about the case.

Those prosecutors said Shkreli’s off-the-cuff remarks, made against the desperate wishes of his lawyers, “risks tainting the jury.”

Prosecutors, who believe that Shkreli has resumed posting on Twitter under a pseudonym despite being banned from the social media platform earlier this year for harassing a female reporter, also want him barred by the judge from tweeting further about the case.