Martin Shkreli sounded uncharacteristically contrite in the letter he wrote to the judge last week, shortly before his sentencing. “I was a fool,” the disgraced pharmaceutical boss wrote in a last-ditch attempt to head off a heavy sentence. “I have learned a very painful lesson.”

On Friday in Brooklyn, Judge Kiyo Matsumoto seemed unconvinced, handing down a seven-year sentence following Shkreli’s conviction last August on charges that he deceived investors in a pair of failed hedge funds. Prosecutors had asked for Shkreli – dubbed the “Pharma Bro” – to be given 15 years in prison. Legal experts said he could easily get 10. Matsumoto said Shkreli had shown remorse, but the case was about an “egregious multitude of lies” and mentioned that Shkreli’s bail was revoked by after he offered a $5,000 bounty for a Hillary Clinton hair – with the follicle.

John Coffee of Columbia law school said Shkreli’s crimes were similar to insider trading, and the longest sentence handed out in such a case is the 11 years given to the hedge fund manager Raj Rajaratnam. Rajaratnam was convicted of trading on illegal tips in the biggest such case brought in decades. That case was “longer-term, more egregious and absolutely predatory”, said Coffee.

So why did Shkreli get nearly as long? Basically, because he acted like a jerk. “His behavior during the trial was arrogant, and he treated the judge as an irrelevancy. Every defense counsel I know, and I know a lot of them, instructs his client to be respectful and modest because ultimately the judge is going to sentence you. Your arrogance can cost you a very high price,” Coffee said.

From his cell at Metropolitan detention center in Brooklyn, New York, Shkreli may well be regretting calling the prosecution “junior varsity”, telling reporters during a break that his critics “blame me for capitalism” and trolling detractors on social media so hard that not only was he banned for life from Twitter but prosecutors called for a gag order to stop him from making “a spectacle of himself and the trial directly on the courthouse grounds”.

Martin Shkreli, left, is shown seated next to his lawyer Ben Brafman in federal court in New York in this courtroom sketch. Photograph: Elizabeth Williams/AP

It could all have been so different. Born in Coney Island, Brooklyn, in 1983 to Albanian immigrants who both worked janitorial jobs, Shkreli was a bright kid who attended New York’s Hunter College high school, a public school for gifted kids whose alumni include the supreme court justice Elena Kagan and the Sex and the City actor Cynthia Nixon, before getting a degree in business administration.

If he had taken another path, he might have been an American business hero. Instead he became the poster boy for excess in the pharmaceutical industry and was dubbed the most hated man in the country.

It all started auspiciously enough. At 17, Shkreli was interning at Cramer Berkowitz, a hedge fund run by the CBNC pundit Jim Cramer (Cramer told Vanity Fair he didn’t remember him) and by 21 he was running his own hedge. He was also running into trouble.

In 2007, a bet with Lehman Brothers on declining markets went wrong and Shkreli refused to pay up. Shkreli was right that markets would tank – but a year later. A suit ensued, but by then Lehmans had declared bankruptcy, the financial crisis had begun, and the suit was vacated.

It was his next venture, a hedge fund called MSMB, that landed him in jail. MSMB invested in biotech companies. According to US prosecutors, Shkreli used “a trifecta of lies, deceit, and greed” to scam its investors, lying about its success and paying them back from another company he owned.

Shkreli was arrested in 2015, taken from his Manhattan apartment in a grey hoodie and handcuffs in a morning “perp walk” in front of the nation’s press, and charged with “widespread fraudulent conduct”.

The charges, however, had nothing to do with the incident that had already made him infamous.

As became apparent in court, most of MSMB’s investors got their money back, and the trial would have been a run-of-the-mill case if it weren’t for Shkreli’s alter ego – Pharma Bro, a villain whose origin story is a tale fit for the comic-book baddy he became.

In 2015, one of his companies, Turing Pharmaceuticals, bought the US rights to Daraprim, a drug that has been around since 1953 and is used to treat toxoplasmosis, an infection that is particularly dangerous for people with Aids and compromised immune systems, as well as pregnant and elderly people. Untreated, it can cause seizures, blindness, birth defects and death.

Outside the US, Daraprim is cheap: it costs $1 to $2 a pill. Patients take two or three pills a day and need treatment for weeks or months. The price in the US was already far higher ($13.50) when Shkreli bought the company in 2015, but overnight Turing hiked the price of Daraprim to $750, a fiftyfold increase. The story became a media sensation and Shkreli became “the most hated man in America”.

What he did wasn’t illegal or even, sadly, all that unusual. Price gouging is a common practice for US pharmaceutical companies.

But while other price hikes have roiled the media, Shkreli remained the poster boy for pharma excess and seemingly revelled in it.

For a short moment it looked like Shkreli could be the impetus for change, and Congress held hearings on drug prices. Shkreli declined to testify but characteristically found time to tweet that members of Congress were “imbeciles”.

For all the shouting, drug laws haven’t changed. The $277m the pharma industry spent on lobbying last year alone probably helped.

And in the meantime, Shkreli managed to keep the attention on himself with a series of increasingly obnoxious stunts. He paid $2m for the one copy of Once Upon a Time in Shaolin by the rap legends the Wu Tang Clan – and then got into a fight with the band. Ghostface Killah called him “Michael Jackson nose kid”. Shkreli retaliated by appearing to physically threaten the rapper in a video where he was flanked my masked goons.

But it was his behavior in court that may well have cost him dearest. “If you are going to be arrogant with a sentencing judge, you are taking your life in your hands,” said Coffee.

Sentencing expert Edward Bales, founder of Justice Solutions of America, said he expected Shkreli would initially be sent to Butner, a facility in North Carolina that holds fraudster Bernie Madoff, for assessment after sentencing. If the authorities rule Shkreli is mentally sound, his threats to Clinton and others could mean a stay in a medium-security prison – alongside gang members and other hardened criminals.

“It’s a whole different ball game when you are threatening government officials. They take that very seriously,” said Bales.