Mayor de Blasio fired the head of the Department of Investigation on Friday, the first time in the agency’s 145-year history that its leader was booted by City Hall.

Letitia James, the public advocate and incoming state attorney general, denounced the move as “Trump-like behavior” and called on the City Council to hold hearings to ensure that ongoing investigations of the administration aren’t swept under the rug.

The ax fell on DOI chief Mark Peters after months of fierce infighting with the mayor, his onetime friend and political ally, and after the agency issued one blistering report after another raising questions about the administration’s competency and honesty.

But in the end, Peters provided de Blasio all the ammunition he needed to sack him. An independent investigation concluded that the city’s chief watchdog had overstepped his powers by trying to grab control of the school system’s investigative office — and de Blasio seized on that finding to justify getting rid of him.

“He and his senior staff offered statements and conducted themselves in a manner indicating a lack of concern for following the law,” the mayor’s termination letter said.

“Commissioner Peters made inaccurate and obfuscating presentations to the First Deputy Mayor [Dean Fuleihan] Further, the findings depict Commissioner Peters as engaging in intimidating and abusive behavior and otherwise conducting himself in a manner that is unbecoming of any public servant.”

De Blasio nominated Margaret Garnett, a former federal prosecutor who now serves as the Executive Deputy Attorney General for Criminal Justice, to run DOI. The Council would have to approve her appointment.

In one terse sentence in a press release about Garnett, the mayor thanked Peters “for his service.”

The firing takes effect Wednesday so Peters can “make a public explanation,” a requirement of the City Charter.

Peters issued a statement saying he would take that opportunity.

“For now, let me say that serving as DOI Commissioner has been the greatest professional honor of my life. DOI’s work over the past five years has exposed corruption and misconduct and forced serious systematic reforms in multiple agencies,” Peters said.

The harshest reaction to Peters’ firing came from James, a one-time ally of the mayor.

“Today’s firing of Department of Investigation’s (DOI) Commissioner Mark Peters is reminiscent of Trump-like behavior. The [investigative] report, while raising concerns, did not call for the firing of Mark Peters. It is my understanding that there are several pending DOI investigations that are particularly troublesome. As such, I am calling on the City Council to conduct an Executive Session with Mark Peters so that he can testify about the status of his pending cases, their impacts on the de Blasio Administration, and what role they may have played in Mark Peters’ dismissal,” James said.

Reaction from key Council members showed that Peters recent actions cost him key supporters.

“As Investigations Commissioner, Mark Peters exposed significant issues at NYCHA, the Administration for Children’s Services and the Mayor’s Office for Contract Services, and I thank him for his service,” said Council Speaker Corey Johnson. “However, the [investigative] report raised questions about his ability to continue in his role.”

But others blasted Peters’ termination.

“I strongly disagree with the Mayor’s firing of Commissioner Mark Peters — an act unprecedented in the 145-year history of DOI,” said Councilman Ritchie Torres (D-The Bronx), who chairs the committee that oversees DOI. “Were it not for the independence of Commissioner Peters, neither the public nor the City Council would have ever known about the suspicious sale of Rivington [nursing home] or the chronic failure of lead compliance in public housing, not to mention countless systemic failures elsewhere in city government.”

Good government groups were initially critical of Peters’ appointment in 2014, worrying there was no way the mayor’s former campaign treasurer would shine a harsh light on City Hall.

But Peters defied expectations by launching a series of investigations that resulted in bombshell reports, which included exposing NYCHA’s lead paint coverup, the NYPD’s failure to properly staff and train sex crime cops and travel abuses by top officials at the Department of Correction.

De Blasio began contemplating axing Peters at least a year ago — and the issue came to a boil when Peters tried to assume control of the Department of Education’s independent watchdog in April.

While the DOE’s Special Commissioner for Investigation is appointed and reports to the DOI chief, the office always operated autonomously until Peters attempted to merge it directly into his agency, triggering a turf war.

Peters eventually abandoned the ill-fated takeover attempt.

The independent investigation into his conduct exposed shocking behavior, including retaliating against employees in violation of whistleblower protections.

While Peters apologized for the behavior, tensions with City Hall only grew worse.

In October, he sent a shocking letter alleging that de Blasio and his top aides asked him to delay some investigations and revealed DOI was probing alleged politically-driven efforts to interfere with the long-running probe into whether yeshivas were meeting state education requirements.

Additional reporting from Carl Campanile, Alex Taylor and Rich Calder