The commander of the NYPD’s troubled sex crimes unit — who was overseeing the Harvey Weinstein investigation — was given the boot and transferred out to Staten Island as part of a major shakeup.

Deputy Chief Michael Osgood has been a “dead man walking” since a scathing Department of Investigation report on the unit was made public in March, a police official said.

The embattled chief was expected to be replaced as the NYPD looked to improve the Special Victims’ Division to “better serve the victims and survivors of sexual assault in New York City,” a police source said.

The DOI report said Osgood’s unit is incredibly understaffed and under-trained despite a recent surge in cases.

It found the problems within SVD over the past nine years resulted in sex crime cases not being properly investigated.

The Special Victims Squad had only 67 detectives handling 5,661 cases in 2017, the report showed.

The lack of staff has been so problematic that in 2011, NYPD leadership directed SVD to “simply not investigate all misdemeanor sexual assaults,” according to the report.

The report also found that certain rape cases were not treated seriously.

A “longstanding policy” existed where “acquaintance” and “domestic” rape were not investigated post-arrest by SVD but instead kept at the local precinct level, it stated.

Osgood will be replaced by 21-year veteran of the NYPD, Chief Judith Harrison, according to police officials.

The unit will be divided into two divisions, with one handling adults cases run by Deputy Inspector Paul Saraceno. There will be a separate child abuse squad run by Deputy Inspector Caroline Roe.

Hate Crimes will no longer fall under the SVD umbrella, “to better focus both missions,” said a police official.

Harrison was the commanding officer of the 109th Precinct before being promoted to deputy chief and assigned to the Detective Bureau.

Osgood’s most notable case during his 8-year tenure atop SVD was the probe into rape allegations against Weinstein.

He reportedly hid one accuser, Italian model Ambra Battilana, from DA Cy Vance because he believed that office was “actively” working to discredit her.

“We decided we’re going to hide the victim,” Michael Bock, a retired sergeant who worked under Osgood, told New York Magazine. “From the DA.”

Osgood was also singled out by a lawyer for Weinstein earlier this month after it was revealed that he interviewed witnesses along with police Detective Nicholas DiGaudio.

The lawyers allege that DiGaudio coached the witnesses, leading prosecutors to abandon the cases. In court papers, DiGaudio was called “a serial obstructor” who was “singularly hell-bent on concealing the truth.”

Weinstein’s lawyers wanted Osgood to testify in respect to the alleged misconduct.

The NYPD reiterated its statement that “the evidence against Mr. Weinstein is compelling and strong” and that it will work “to deliver justice for the courageous survivors who have bravely come forward.”