NEW YORK — In the two years since bursting onto the national scene, Martin Shkreli has often appeared to be his own worst enemy.

When the public lashed out at the former hedge fund manager for raising the price of a critical drug 5,000 percent, he heckled them as uninformed. Hauled before Congress, Shkreli smirked and refused to answer questions. Then, he called the lawmakers “imbeciles.”

Even after a Brooklyn jury convicted him of defrauding his investors last month, Shkreli continued to use social media to interact with fans — and detractors. He needed a strand of Hillary Clinton’s hair, he told his 70,000 Facebook followers recently, and was willing to pay $5,000 for it.

Now, it appears Shkreli’s loquaciousness could be the biggest hurdle to his legal prospects.

On Wednesday, U.S. District Judge Kiyo Matsumoto revoked his $5 million bail and said he would spend the next four months awaiting his sentencing in a federal prison. Shkreli’s post on Clinton and other online commentary about female reporters show that he is a threat to the community, Matsumoto said. “This is a solicitation of assault. That is not protected by the First Amendment,” she said of the Clinton post, which also caught the attention of the Secret Service.

By early Thursday morning, Shkreli had been assigned an inmate number at the Metropolitan Detention Center in Brooklyn, a prison housing nearly 2,000 male and female inmates that has been the subject of criticism from judges and attorneys for its poor conditions.

Shkreli and his attorneys have said they would appeal his conviction on three counts of securities fraud, which carry a potential sentence of 20 years. But even if the convictions stood, Shkreli has said he was likely to be sentenced to little or no jail time in a minimum security facility.

That now appears much less likely, legal experts say.

“Shkreli has again proven he’s his own worst enemy [and] … doesn’t have the impulse control needed to keep him out of jail,” said James Goodnow, an attorney with Fennemore Craig, a corporate defense firm. “Shkreli’s conduct is a textbook case of everything you shouldn’t do as a defendant in a criminal case.”

Matsumoto’s willingness to revoke Shkreli’s bail may indicate she is open to giving Shkreli a longer prison sentence and decided that given his bad behavior he should start his time behind bars immediately, legal experts said. “This is not a good sign of what the judge might be thinking” in terms of sentencing, said Ira Matetsky, a partner at New York law firm Ganfer & Shore.

Shkreli, 34, is best known for raising the price of Daraprim — a 62-year-old drug primarily used to treat newborns and HIV patients — from $13.50 to $750 a pill, but he was convicted by a Brooklyn jury of defrauding the investors in his hedge funds. Shkreli lied to obtain investors’ money, then didn’t tell them when he made a bad stock bet that led to massive losses, prosecutors argued. Instead, they said, he raised more money to pay off other investors or took money and stock from a pharmaceutical company, Retrophin, he was running.

In white collar cases such as Shkreli’s, the sentence is usually meted out in proportion to the losses faced by their victims. Shkreli’s hedge fund investors actually made a hefty profit, which would typically work in his favor, legal experts say. But his out-of-court antics may have crushed those prospects. Matsumoto appeared at times angry and confused by Shkreli’s conduct, and the judge ignored repeated pleas by his attorneys to give him another chance.

“I got the strong sense that for the judge this was the straw that broke the camel’s back,” said David Chase, a former prosecutor for the Securities and Exchange Commission. “The judge still retains some element of discretion. This post-trial conduct will not help him.”

Shkreli has also inadvertently inserted himself into a larger debate about when a person’s online persona deserves real-world consequences. His attorneys argued that while “stupid” and “unfortunate,” his comments on Facebook did not amount to a threat. He has never been violent and did not expect anyone to take him seriously, they said.

But prosecutors noted that the Secret Service took his comments seriously enough to increase Clinton’s security and they noted Shkreli could not guarantee that one of his followers, seeking the $5,000 payoff, fame or just Shkreli’s approval, might not act on his behalf.

The same comments made by someone other than Shkreli likely would not have attracted the same level of attention or legal consequences, experts said. “But the context here is different. This comes on the heels of a lot of other [questionable] conduct,” said Matetsky.

More on Martin Shkreli: