A New York University law school professor struck it rich, raking in $8.3 million from the university thanks to a sweetheart real estate deal.

Richard Stewart, who heads the Frank J. Guarini Center on Environmental, Energy, and Land Use Law, reaped the windfall from the 2017 sale of a townhouse on Charles Street where he had lived since the 1990s, NYU’s latest tax filings show.

The 4,600-square-foot home was sold in July 2017 for $15 million to an entity called Le Petit Francozuelan LLC, city records show.

Under a 1996 deal with the NYU School of Law Foundation, which then owned the townhouse, Stewart had the right to purchase the property at an unspecified price, according to NYU’s tax filing.

In 2017, Stewart transferred his option to “A third party who purchased the townhouse,” the tax form says.

“In that sale, the university received the amount established under the agreement formula, and Professor Stewart received the balance of the proceeds of the sale,” the tax filing said.

NYU spokesman John Beckman called the deal “a one-time matter involving the sale of a property that served as faculty housing for over two decades, and both the university and the faculty member involved realized significant gains from the sale of the property compared to the original purchase price.”

He wouldn’t say what NYU, one of the nation’s most expensive colleges, did with its share of the proceeds. Tuition and room and board at the school is $72,000 this year.

The school has come under scrutiny for the lavish perks it has heaped upon faculty and administrators, including providing loans to buy both primary residences and vacation properties.

John Sexton, the university’s former president, got a $600,000 loan for a Fire Island beach house, according to a published report.

Richard Revesz, the former NYU Law School dean, and his wife, Vicki Been, who was just named deputy mayor for Housing and Economic Development, own a West Village townhouse financed through the School of Law Foundation, records show.

They also own a second home in Litchfield County, Ct.

As of Aug. 31, 2016, they owed NYU $6.57 million, a sum that appears to have later been paid off, according to NYU’s latest tax filing.

NYU law professor Daniel Shaviro also lives in a university-owned townhouse on Charles Street, but told The Post he pays market rent and does not have an option to buy it

“I’m glad I don’t know how much he made from that,” he said of his colleague. When told, he said, “Wow.”