He managed to avoid federal charges himself but Mayor de Blasio may yet wind up testifying at a political corruption trial.

After opening statements in the Long Island trial of former Nassau County Executive Ed Mangano Wednesday, a defense lawyer said he may well call de Blasio to the stand.

Marc Agnifilo, who represents co-defendant and former Oyster Bay Town Supervisor John Venditto, said he might call on the Big Apple mayor to answer questions about the prosecution’s star witness, crooked ex-restaurant owner Harendra Singh.

“We’ll see what Singh testifies to, in terms of [de Blasio], and probably make a decision from there,” Agnifilo said outside court.

During a closed court appearance in 2016, Singh testified that he bribed de Blasio with tens of thousands of dollars in campaign contributions so the mayor and other officials would arrange a “favorable” renewal of the lease on his since-shuttered Water’s Edge restaurant in Long Island City, Queens.

Long Island federal Judge Joan Azrack ruled last month that defense lawyers can cross-examine Singh about those allegations, but not that de Blasio was never charged by federal prosecutors and the Manhattan District Attorney’s Office following lengthy investigations.

Singh is scheduled to take the stand Thursday for the first of at least two days of testimony.

De Blasio has vehemently denied Singh’s claims, saying: “This guy, to save his own skin, struck a plea deal with the federal prosecutors …he agreed to certain charges for his own self-preservation.”

Agnifilo also said Singh was introduced to de Blasio by lawyer Thomas Garry, who specializes in publicly financed economic-development projects and helped Singh obtain loan guarantees from Oyster Bay.

Garry donated a total $3,150 to de Blasio’s 2009 campaign for public advocate and 2013 campaign for mayor, records show.

He also hosted five political-fund raisers for de Blasio between 2010 and 2013.

De Blasio spokesman Eric Phillips said: “The mayor’s got nothing to do with that case and we don’t know anything about what the lawyer’s saying.” Garry didn’t respond to an email seeking comment.

In openings, prosecutor Lara Treinis Gatz said Mangano’s wife, Linda — who’s also on trial with her husband and Venditto — was paid $450,000 over four years by Singh for a no-show job as a “food taster” at Water’s Edge.

Gatz said that Singh made those payments were among a “never-ending flood of kickbacks” that Singh paid the defendants “in exchange for lucrative contracts and other official actions.”

The graft included a $7,300 Panerai Luminor watch that the Manganos re-gifted to one of their sons on his 21st birthday, she said.