Two of the NYPD cops charged with helping protect a prostitution racket run by a retired vice detective are eligible for hefty pensions — as long as they retire before their potential convictions.

Officer Giancarlo Raspanti — who’s accused of getting “discounted” sex at brothels run by ex-Detective Ludwig Paz — and Sgt. Louis Failla both have more than 20 years on the job, which qualifies them for full retirement benefits.

Raspanti, who joined the NYPD in July 1996, earned $135,333 during fiscal 2017, while Failla, who was hired in December 1997, earned $132,661, records show.

NYPD cops with 20 or more years of service are guaranteed their pensions unless they’re convicted of a felony while on the city payroll.

Among those who have benefitted from the sweetheart deal are “Mafia cops” Louis Eppolito and Stephen Caracappa, who were convicted in 2006 of committing eight murders while secretly working as hit men for the Lucchese organized-crime family.

Caracappa died in prison last year, but Eppolitio is still drawing his pension while serving a life sentence in a federal lockup in Tucson, Ariz.

Raspanti and Failla are among seven cops who were released without bail after pleading not guilty Thursday in connection with a sprawling hooker ring allegedly headed by Paz and his wife, Arelis Peralta, who are also accused of running illegal lottery operations.

Peralta’s daughters, Jarelis Guzman, 22, and Arisbel Guzman, 20, were also charged in the alleged rackets and were also released without bail.

Both sisters live with their parents in Queens Village, where two women and two men with covered faces were spotted leaving the family home in a white Mercedes-Benz sedan and a white Range Rover on Friday morning.

A neighbor said the family “always seemed very cheerful” and the Range Rover “was a wow thing and all the kids stopped to look at it” when Paz first brought it home.

“I just assumed he was a car dealer,” she said. “You never know how people come into money.”

Paz and Peralta were being held on $525,000 bond or $325,000 bail and $400,000 bond or $150,000 bail, respectively.

Additional reporting by Georgett Roberts