The ex-vice detective who used NYPD cops to protect his $2 million-a-year prostitution racket made sure all prospective johns dropped their pants and got groped — to prove they weren’t undercover officers, officials said Thursday.

Ludwig Paz, 51, knew from his years on the job that cops can’t expose themselves to hookers during sting operations, so any new clients who wanted to patronize his cathouses had to undress and “allow themselves to be fondled,” Queens District Attorney Richard Brown said.

The head of the NYPD’s Internal Affairs Bureau also said some of Paz’s alleged police accomplices romped with his prostitutes while on duty as payment for funneling information to him about “active and ongoing” investigations. “They patronized prostitutes on and off duty,” IAB Chief Joseph Reznick said.

During arraignments of the seven current cops charged in the case, Queens prosecutors said customers at Paz’s brothels were charged $40 for 15 minutes of sex, $80 for a half-hour or $160 for a full hour, with half the cash going to the hookers. But two of the cops accused of scheming with Paz — Sgt. Carlos Cruz and Officer Giancarlo Raspanti, 43 — were rewarded with cut-rate sexual favors, prosecutors said.

Cruz, 41, was seen visiting Paz’s brothels “countless times” but would only have to “give the girl a 20,” Queens Assistant District Attorney Bradley Chain said. In exchange, the married father of two provided Paz with information he obtained on his own and also from other cops, Chain said.

Raspanti — a 23-year veteran and divorced dad who lives in his childhood Brooklyn home — allegedly searched NYPD databases to help Paz keep from getting busted. He also paid just $20 to each of the gals that serviced him, ADA Christine Oliveri said.

Paz allegedly paid Brooklyn South Vice Detective Rene Samaniego, 43, as much as $500 a week to serve as his “primary informant,” with Samaniego allegedly tipping Paz to upcoming raids and undercover operations.

Samaniego’s info included details on “what officers were coming at what time, what they were wearing, where they were coming from” — and was sometimes provided while he was stationed outside a brothel as part of an NYPD investigation, Chain said.

Samaniego also allegedly “leapt to action” when he learned one of Paz’s hookers was the subject of a trafficking probe, alerting her pimps and coaching them on what to say to keep Brooklyn prosecutors from bringing charges.

“This conduct is egregious. It is far beyond any of the other officers who were charged here today,” Chain said.

Other cops charged in the racket include Detective Giovannni Rojas-Acosta, 40, and Sgt. Louis Failla, 49, who law-enforcement sources said was formerly Paz’s boss in the Vice Enforcement Division. In 2009, Failla gave Paz a 5.0 — the highest score possible — on his annual NYPD performance review, with one source noting: “No one gets a 5, even the inside people.”

Brothers Sgt. Cliff Nieves, 37, and Officer Steven Nieves, 32 — were accused of running what prosecutors called a “pop-up brothel,” with Steven Nieves allegedly caught on video accepting money from men when they entered.

That operation — which allegedly used one of Paz’s locations and his prostitutes — was “for the sole purpose of hosting a bachelor party,” DA Brown said.

Officials said Paz and his wife, Arelis Peralta, 43, oversaw brothels in Queens, Brooklyn and Hempstead, LI, and also ran illegal lottery operations out of two beauty salons, a deli and other undisclosed locations.

The brothels alone allegedly generated more than $2 million between August 2016 and September 2017.

The rackets were allegedly a family affair, with Peralta’s daughters, Arisbel Guzman, 20, and Jarelis Guzman, 22, busted along with their mom and step-dad, with whom they live in Queens Village.

Arisbel is accused of acting “in whatever way her family needed,” at times serving as “an attendant collecting money from the patrons,” while Jarelis is alleged only to have worked “as a runner to pick up gambling proceeds,” ADA Chain said.

IAB Chief Reznick said Paz, who retired in 2010, apparently “familiarized himself with the operation of gambling and prostitution, and he just took a favor to that type of business” after working as a vice detective.

The investigation of Paz, his alleged NYPD accomplices and nearly three dozen civilian co-defendants — dubbed “Operation Zap” — took more than three years due to its highly sensitive nature, Reznick said.

“Unlike many other types of investigations, internal investigations require the highest level of confidentiality and very discreet methods of obtaining records and various things that we needed during the course of our investigation,” Reznick said during an afternoon news conference at NYPD headquarters in lower Manhattan.

“Any leaks about our cases could have [had] detrimental effects.”

Investigators monitored more than 50 wiretaps, conducted more than 100 surveillance operations and “just as many undercover operations,” he said.

Reznick said the probe began in April 2015, based on a tip from a cop who suspected “that someone who may be involved in illegal activities was having conversations with someone in the Vice Enforcement Division.”

“That someone turned out to be a retired detective: Ludwig Paz,” Reznick said.

NYPD Commissioner James O’Neill said the cops busted in the scheme “tarnished the NYPD shields that they wore” and “diminished the great work of tens of thousands of honest, honorable and ethical cops.”

“Am I angry? Of course I’m angry, as are all 36,000 hardworking cops,” O’Neill said.

All of the cops and Peralta’s daughters were released without bail after pleading not guilty in Queens Supreme Court.

Paz was held in lieu of $525,000 bond or $325,000 bail; and Peralta on $400,000 bond or $150,000 bail.

Additional reporting by Larry Celona and Georgett Roberts