A former NYPD homicide detective will spend four years in federal prison for scheming to defraud the federal government out of millions in small-business COVID relief funds.

Detective John Bolden, 47, a 20-year NYPD veteran who retired from the force in October, schemed to fleece the federal Paycheck Protection Program, which offered loans to small businesses forced to close or at risk of closing during the COVID pandemic. Loans would be forgiven if they were spent on job retention efforts and payroll costs.

Bolden pleaded guilty in February to wire fraud conspiracy. He admitted to preparing fake applications for 65 people, including himself, co-conspirator former Detective Anthony Carreira, his family members and clients of his tax preparation service. The scheme cost the government more than $3 million, federal prosecutors said.

Brooklyn Federal Court Judge Diane Gujarati handed down the ex-cop’s sentence Wednesday.

Bolden, of Valley Stream, L.I., was asking for no jail time, with his lawyer, in a letter to the judge, calling the scheme a “lapse in judgment” driven by financial woes.

“Unable to bring himself to tell his wife that he had dumped their savings into two failed businesses while the family was drowning in debt, John Bolden did the unthinkable in hopes of keeping his failing businesses afloat and restoring his family’s savings,” his attorney, Esere Onaodowan, wrote in an April sentencing memo.

Prosecutors countered that Bolden’s actions were no momentary lapse, since the scheme spanned years and he “corrupted multiple members of the NYPD.”

Gujarati said that Bolden showed genuine remorse, but that his “brazen” conduct required a sentence that would deter others from taking a similar path.

“Despite being a police officer sworn to uphold the law, the defendant organized a scheme that enabled dozens of individuals, including clients, family members and NYPD co-workers, to obtain millions in federal funds using fictitious tax records,” U.S. Attorney Joseph Nocella said Wednesday. “Bolden brazenly took advantage of a COVID relief program created to help struggling businesses survive an unprecedented national crisis.”

Bolden will also have to pay more than $303,000 in restitution and forfeit another $112,000.

The scheme started in May 2020, after Borden heard an audio recording from another fraudster giving other tax preparers advice on how to game the Paycheck Protection Program.

He tried it himself, putting in bogus applications for himself, other cops — including Carreira, who was sentenced to time served in March — his cousin and his mother.

Bolden and Carreira each got more than $40,000 for making up fake “Security Services” and “Armed Security” businesses, while his mother, Jacqueline Johnson, created a company called “Hair by Jacqueline,” and his cousin Christian McKenzie invented a phony sneaker business called “Chris Kicks,” according to court documents.

Bolden also had Johnson and McKenzie recruit others willing to put their names on fake applications, taking a $4,000 cut of each successful loan, according to the feds.

McKenzie will be sentenced July 14. Though Johnson was initially arrested, prosecutors declined to pursue charges against her.