A felon who was once the richest man in China has just purchased a $41.5 million townhouse on the Upper East Side, The Post has learned.

Huang Guangyu won’t be able to use it for a while, though. He’s currently living in a Chinese prison cell, serving a 14-year sentence for bribery and insider trading.

The former golden boy — once known as the “Bill Gates” of China — and his wife Lisa Du Juan closed on the townhouse this week. They hid their names under an LLC, which the US Justice Department has been cracking down on amid complaints that criminals are laundering cash through real estate in New York, Miami and Los Angeles.

“[Huang] is kind of like the Al ­Capone of China, running his business from behind bars,” quipped a real estate industry professional with inside knowledge of the deal.

The 19th century limestone mansion on East 76th Street was sold by Japanese philanthropist Bun­go Shimada, who originally listed the home for $50 million.

The six-story neo-Renaissance home, known as the Clarence Whitman Mansion, was built in 1898. It has a second-floor iron balcony and a clay-tiled mansard room, plus nine bedrooms over 14,000 square feet, an elevator — and all sorts of secret passageways.

A floor in a coat closet opens to reveal hidden stairs that descend to the basement, while the library has a secret door that leads to a card room.

There’s also a gym and a penthouse floor with a solarium and a terrace.

Huang was born of peasant stock in southern China and built a massive Walmart-style electronics empire from a single street stall in Beijing. He then moved into Chinese real estate. Forbes ranked him China’s richest person in 2006 and 2007, though he had slipped to third place by 2008, the year he was arrested on suspicion of fraud.

In August 2009, the Hong Kong High Court ordered the freezing of $280 million of assets belonging to Huang and Du Juan’s company, Gome Electrical Appliances Holding Ltd.

Huang was sentenced to 14 years by a Beijing court in 2010. Du Juan was given a three-year sentence in 2010 but did not serve jail time.

The couple remain Gome’s largest shareholders, and by 2015, China Daily reported that Huang’s company booked close to $1 billion in gains.

Du Juan worked with multiple brokers over the past few years as she house-hunted in Manhattan, sources said. Stan Ponte, a broker with Soth­eby’s International Realty who had the listing, did not return calls.