A retired NYPD vice detective and his wife have been indicted on charges they ran a prostitution ring and gambling operation with the aid of seven current police officers and dozens of civilians.

Prosecutors on Thursday say 51-year-old Ludwig Paz operated brothels in Queens, Brooklyn, and Nassau Counties and numerous gambling rooms set up inside beauty parlors and other businesses.

They say the retired detective used his inside knowledge of NYPD vice procedures to thwart detection. Information on his lawyer wasn't immediately available.

The officers, whose arrests were announced Wednesday, are accused of helping Paz operate the illicit businesses. Prosecutors said one of the officers provided confidential police information in exchange for discounted sex.

The defendants face various charges including enterprise corruption, official misconduct, and promoting prostitution.

According to sources, three of the defendants are sergeants, two are detectives, and two are police officers assigned to commands in Brooklyn and Queens. Sources said two other detectives have also been placed on modified duty.

The NYPD said some of the officers had sex with the prostitutes while they were on and off duty.

Officials said the officers charged not only tipped off the brothels about upcoming raids, but they also targeted competing prostitution rings so they could be investigated.

Sources said some 40 civilians were also arrested in connection to this case, and also said this ring provided private protection to this criminal operation.

In a statement Police Commissioner James O'Neill said, "Those who swore an oath and then betrayed it have felt the consequences of that infidelity."

Authorities said the investigation started after an NYPD officer caught wind of what was going on and alerted the department's Internal Affairs Bureau in April 2015.

Officials said the investigation is ongoing, although police said they were not expecting to arrest any other officers.