Manhattan’s top sex crimes prosecutor — who came under fire for how she handled a 2015 claim against Harvey Weinstein — decided to retire days before a jury weighs charges against the fallen movie mogul.

Martha Bashford, 65, submitted her resignation letter on Friday, telling District Attorney Cyrus Vance Jr. that “40 years is a long time to stay in one place, and it is time for me to give notice that I will be moving on,” according to a copy obtained by The Post.

The move came more than two years after Bashford lost oversight of the high-profile case against Weinstein amid tensions between the NYPD and the District Attorney’s Office that led then-Chief of Detectives Robert Boyce to publicly question Vance’s judgment.

Vance has said he followed Bashford’s recommendation to not charge Weinstein over allegations he groped Filipina-Italian model Ambra Battilana in 2015.

Bashford’s retirement, effective March 20, wasn’t tied to the Weinstein case, according to a Vance spokesperson.