Mayor de Blasio pushed the city Department of Investigation to quash reports exposing failures in his administration, the agency’s recently fired chief alleged in an explosive letter on Monday.

The arm-twisting from City Hall included “a late-night screaming call” from the mayor, pressure to keep damaging reports under wraps — and an NYPD official flashing a gun for intimidation, outgoing DOI Commissioner Mark Peters wrote in the letter to City Council leaders.

De Blasio booted Peters on Friday for allegedly violating whistleblower laws in his attempt to take over the Department of Education’s investigations division.

But Peters said Hizzoner actually terminated him in retribution for past investigations and to blunt ongoing probes.

“These incidents demonstrate a pattern in which the mayor and his senior staff believe that I owe a duty of loyalty to the mayor rather than to the city as a whole and that my actions, in exposing waste, fraud or abuse in city agencies . . . are improper and justify retribution,” Peters wrote.

The letter chronicles two years of increasingly fractured relations between de Blasio and Peters — a onetime friend who served as his campaign treasurer in 2013 — as the DOI issued one blistering report after another exposing failings and wrongdoing at city agencies.

Peters claimed de Blasio called him hours before he released a January 2017 report into major problems at the Administration for Children’s Services following a toddler’s death and asked him not to publish the findings.

When Peters refused, he said, de Blasio grew irate, accused him of trying to bring his administration “down” and then said he was “going to hang up now before I say something I shouldn’t.”

The following day, Peters said, he was summoned to a meeting with First Deputy Mayor Anthony Shorris and City Hall staff.

“I was pointedly told that the report would be embarrassing to the mayor and asked, in a way that made me extremely uncomfortable, whether I was really prepared to do that,” he wrote.

The pattern repeated in April 2017 as the DOI prepared to expose Department of Correction boss Joseph Ponte for using his city car and driver for personal travel, Peters alleged.

Shorris allegedly asked Peters to “forbear” issuing the report because it would embarrass Ponte, and Peters said he later heard that “the mayor and his senior staff were ‘really angry,’ felt I should be more ‘loyal,’ and now wondered if I was ‘still a friend.’ ”

And as the DOI prepared its report laying out the New York City Housing Authority’s years-long failure to conduct lead inspections, as well as then-Chairwoman Shola Olatoye’s false claims that it had, he alleged Shorris applied pressure again.

“When I informed him that DOI could not withhold this report related to public safety issues . . . he became annoyed and informed me that in his view, as a city commissioner, I had an obligation to comply with his request to protect the interests of the agency in question, NYCHA,” Peters wrote.

Five days after the DOI released its NYCHA investigation, The Post reported that de Blasio wanted Peters canned.

Peters claimed City Hall’s interference also impacted DOI probes into the NYPD, which he says repeatedly withheld documents and witnesses.

At a 2016 meeting of DOI, City Hall and NYPD officials about the lack of cooperation, Peters alleged, an unnamed senior police official “conspicuously displayed his gun” and later “told a third party that he had done so to intimidate the DOI officials.”

He claims neither Shorris nor the city’s top lawyer, Zachary Carter, objected to that behavior. Instead, Peters claimed, Shorris called him an “a- -hole” for insisting the NYPD produce documents.

In the letter, Peters warned that his ouster would have a “chilling effect” on his successor as he confirmed the DOI still has ongoing probes into NYCHA, the NYPD and alleged City Hall interference into the Department of Education’s review of yeshivas.

De Blasio denied he or others asked Peters to spike reports.

“It’s just false. I’m sure I had conversations with Mr. Peters, and I’m sure I had disagreements, but that characterization is false,” he said at an unrelated press conference.

“Look, unfortunately this is an individual who did some very inappropriate things . . . Those characterizations are not fair and not accurate.”

Hizzoner said there were “conversations” about reports regarding “accuracy” and “specific recommendations” but never an “effort to inhibit the actions of DOI on a specific report.”

He argued it was “100 percent appropriate” for City Hall to “debate what to do about findings.”

City Hall staked Peters’ firing on a report Peters himself commissioned. It found he violated whistleblower laws by retaliating against staff at the DOE investigative office who questioned his effort to take over their operation.

In his letter, Peters argues that the report “simply does not provide the mayor with a proper reason for removing me” and that it was riddled with errors.

The mayor has nominated Margaret Garnett, a top official in the Attorney General’s Office, to replace Peters, pending approval by the City Council.

The City Charter grants a DOI commissioner the right to reply if fired but offers no provision for contesting such a termination.

Councilman Ritchie Torres, who chairs the council’s investigations committee, and Speaker Corey Johnson expressed alarm at Peters’ allegations but treated his departure as a fait accompli.

“The letter in question reveals a pattern of interference with DOI investigations and intimidation against DOI officials that borders on the unethical and should be illegal,” Torres said in statement.

Additional reporting by Ruth Brown