A notorious inside trader who was slapped with a then-record 11-year prison term in 2011 was quietly released to home confinement in his swank Upper East Side apartment this summer — thanks in part to Kim Kardashian.

Ex-billionaire Raj Rajaratnam was released early for good behavior, but didn’t have to move into a seedy halfway house full of other ex-cons as do most federal felons released early.

That’s because Rajaratnam, 62, whose estimated worth in 2010 was $700 million, qualified for special treatment under the “First Step Act,” a series of criminal justice reforms that President Trump signed into law last year after Kardashian lobbied for it in the Oval Office.

One provision allows some federal inmates who are over 60 years old, or who face terminal illnesses, to serve the end of their sentences at home, according to Bloomberg News, which first reported Rajaratnam’s release.

The kid-gloves treatment marked the second big break scored by the former head of the Galleon Group hedge fund, who built an ill-deserved reputation as one of Wall Street’s savviest tech investors.

Rajaratnam had faced more than 19 years behind bars following his conviction for scamming more than $70 million in “gains and losses avoided” with the help of carefully cultivated sources who leaked him corporate secrets.

Fellow inside trader Michael Kimelman, who was busted three weeks after Rajaratnam and served 15 months in federal prison, called Rajaratman “one of those seminal cases that defined an era.”

“Raj was clearly breaking the law. This wasn’t a gray area. He was in the black,” said Kimelman, the co-founder of Incremental Capital and author of the memoir “Confessions of a Wall Street Insider.”

In announcing his arrest, then-US Attorney Preet Bharara likened Rajaratnam to the sleazy Gordon Gekko character in the 1987 movie “Wall Street,” twisting Oscar-winning actor Michael Douglas’s classic “Greed is good” line into “Greed, sometimes, is not good.”

The initial criminal complaint against Rajaratnam alleged that he made about $20 million through insider trading on companies including Advanced Micro Devices, Clearwire and Akamai.

Prosecutors said he’d been under investigation for about two years, following a tip from a cooperating witness — later identified as stock trader Roomy Khan — who admitted providing information that helped Rajaratnam make $12.7 million in profits on Polycom, Hilton Hotels and Google.

In exchange, Rajaratnam provided Khan with inside information that he’d obtained from execs at other companies, authorities said.

When Rajaratnam was sentenced, then-Manhattan federal Judge Richard Holwell granted the portly white-collar crook leniency due to his “advanced diabetes leading to imminent kidney failure” and his “need for transplant surgery.”

Rajaratnam’s 11-year sentence still set a record for inside trading, but was surpassed the following year, when lawyer Matthew Kluger was slapped with a 12-year term by a New Jersey federal judge.

Rajaratnam served his time on the top floor of the Federal Medical Center in Devens, Mass., a minimum-security section of the federal prison overlooking Mirror Lake outside Boston.

His digs there included an electrically operated bed, a private bathroom and television, according to reports.

Rajaratnam even had a “manservant” named Eddie who pushed him around in a wheelchair, The Post reported in 2013.

He got sprung about six weeks ago, Bloomberg reported, and is now holed up in an 18th-floor pad on Sutton Place.

Every apartment in the luxury, full-service building features a terrace view of the East River.

In addition, there’s a private garden with a foliage-and-flowers labyrinth, a massive Italian bronze statue in the lobby, a health club, a large radiantly heated driveway and an underground garage with a guaranteed parking rate of $238 per month, according to online listings.

A woman who answered the phone at Rajaratnam’s apartment Monday said he wasn’t home, then hung up when a Post reporter identified himself.

Bharara, who oversaw Rajaratnam’s prosecution during a high-profile crackdown on insider trading, didn’t return a request for comment.

Others bagged during Bharara’s anti-corruption campaign included Rajat Gupta, a former Goldman board member, former IBM exec Robert Moffat and beauty queen-turned-stock trader Danielle Chiesi, who got tips from Moffat while they had an affair.

Rajaratnam’s case was among the first in which authorities gathered evidence of inside trading through the use of wiretaps, which until then had been used primarily to bust mobsters and other organized criminals.

At its peak, Galleon Group was worth as much as $7 billion, and Rajaratnam’s personal fortune was estimated at $1.3 billion by Forbes in 2009, the year he was busted.

The following year, the financial magazine downgraded his net worth to $700 million.

In addition to prison time, Rajaratnam was ordered to pay a $10 million fine and forfeit $53.8 million in ill-gotten gains.

Court records show he paid the fine shortly before reporting to prison, and in 2017 lost a bid to “vacate, reassess, and amend” the forfeiture order.

His former lawyer, John Dowd — who infamously flipped the bird to a CNBC reporter on video following the guilty verdict — said he believed Rajaratnam had been rehabilitated.

“Raj was an outstanding member of the institution and did a great deal to help his fellow inmates, and I think that will be a credit to him,” said Dowd, who represented President Trump during the Russia probe before resigning over a difference in strategy.