Mayor de Blasio is itching to fire his investigations chief for exposing a slew of administration foul-ups — but hasn’t pulled the trigger because it could prompt a messy and unprecedented public hearing, The Post has learned.

Multiple City Hall sources said Hizzoner has wanted for months to replace Department of Investigation Commissioner Mark Peters — a former friend and ally — who last week revealed that Housing Authority boss Shola Olatoye falsely told the feds that 55,000 apartments had been checked for lead-paint hazards.

That report followed others that ripped the Administration for Children’s Services over the slayings of several kids, and faulted the Mayor’s Office of Contract Services and others for letting a Lower East Side nursing home at 45 Rivington St. get turned into luxury condos.

“It’s no secret around here that the mayor would love to get rid of him,” one source said.

“The problem is Peters won’t go quietly, and the mayor is concerned about a knock-out, drag-out fight that could completely derail his final four years in office.”

Peters’ aggressive pursuit of official malfeasance has surprised many observers who expected him to be more of a lapdog than a watchdog after serving as de Blasio’s campaign treasurer in 2013.

But the former state prosecutor and civil-rights lawyer established his independence despite having established a friendship with de Blasio when they both served on a Brooklyn school board in Park Slope during the late 1990s.

The relationship began unraveling in June 2016 when the mayor sided with then-Police Commissioner Bill Bratton over a DOI report that questioned the effectiveness of Bratton’s “broken windows” anti-crime strategy — and has steadily eroded with the release of subsequent reports, sources said.

“The mayor is furious. Their friendship is over,” one source said.

An obscure provision in the City Charter — which applies only to the head of DOI — would require de Blasio to explain his reasons for firing Peters in writing to the Department of Citywide Administrative Services.

And even if he did that, Peters would still be able to fight his firing by demanding a public hearing at which he could make his case for keeping his job, sources said.

The rules have never been tested in the 144-year history of DOI, sources said.

“This is uncharted territory,” another City Hall source said.

“Any move by the mayor to remove Peters at this point would be seen as political payback, and the last thing [the mayor] would want is for this fight to be aired out in public.”

Peters’ high-profile probes have also led to speculation he’ll eventually seek public office, with one source saying: “Peters is and has always been his own person, and he is setting himself up for his own future.”

Asked about Peters’ future with the de Blasio administration, mayoral press secretary Eric Phillips said, “The mayor values the important work DOI performs every day.

“We do not comment on personnel matters or gossip from unnamed sources who clearly aren’t involved in these types of discussions,” he added.

In a statement, Peters said he was “fully engaged in the present and focused on my work at DOI.”

“DOI strikes the difficult balance of providing oversight while also working with agencies to remedy corruption vulnerabilities and improve operations,” he said.

“At the end of the day, DOI’s job is about the work we get done, and the record speaks for itself.”

Additional reporting by Bruce Golding