It was a sweeping and complex criminal enterprise: brothels in Brooklyn, where 15-minute sexual encounters added up to more than $2 million in profits in a 13-month period, and nail salons in Queens, where managers, runners and agents placed bets in an old-school numbers racket.

And the mastermind was a retired New York City police detective who recruited at least seven police officers acting as foot soldiers, according to court documents charging the group on Thursday.

The accusations amount to one of the largest scandals to hit the New York Police Department in recent years, a throwback to corruption dating to the 1950s, when a Brooklyn bookmaker enlisted officers as muscle for his $20-million-a-year operation.

In the new indictment, two brothers who are officers in the Police Department were even charged with holding a bachelor party in a brothel. “They got the place for nothing and they used the prostitutes,” said Deputy Chief Joseph J. Reznick, commander of the Internal Affairs Bureau.

“As we sit here today, the reality is that a number of our uniformed members of various ranks tarnished the N.Y.P.D. shields that they’ve worn,” said the police commissioner, James P. O’Neill, at a news conference on Thursday. “They’ve ruined their own careers and reputations. More importantly, they have diminished the great work of tens of thousands of honest, honorable and ethical cops. And that should make every cop who has ever done this job angry.”

In all, three sergeants, two detectives and two officers have been charged in the prostitution enterprise. Twenty-six civilians were also arrested, and at least 13 more are being sought. Officials said there are no expectations that other police officers will be arrested unless new information surfaces.

The man accused of being the group’s ringleader, Ludwig Paz, 51, a former vice detective, used his knowledge of the workings of the Police Department to his advantage, prosecutors charged.

He knew that undercover officers investigating prostitution are not allowed to expose their genitals during their interactions with suspects, and so he made a rule to check new customers of the brothels: He insisted that the men “undress and allow themselves to be fondled to pass the brothel’s security screening,” the Queens district attorney’s office, which is prosecuting the officers and dozens of civilians, said.

“The evidence in this case is overwhelming,” Bradley Chain, the senior assistant district attorney on the case, said at the officers’ arraignment on Thursday in State Supreme Court in Queens. “There are thousands of hours of surveillance.”

All seven police officers pleaded not guilty and were released on their own recognizance. The courtroom was full of the officers’ family members. Some wept.

“It’s bad,” said a senior commander, who, like others, spoke on the condition of anonymity because the investigation was continuing. Another said “a clear mix of anger and embarrassment” was swirling through the uniformed ranks.

“That fellow cops would stoop so low, for so little and that they would betray the oath and the badge for nonsense,” the commander said.

Officers were accused of tipping off Mr. Paz to ongoing police investigations that could involve his brothels, prosecutors said. Others were accused of providing Mr. Paz information in exchange for discounted sex at a brothel. One detective, Carlos Cruz, 41, was allowed to pay $20 for an encounter with a prostitute that would normally cost $40, prosecutors said. The investigation began after a tip from a police officer.

Image

Detective Rene Samaniego was described by the prosecutor as the worst offender in State Supreme Court in Queens on Wednesday.CreditUli Seit for The New York Times

During the court proceeding, the prosecutors described how Mr. Paz used tips and inside information from the police officers to thwart investigations into his brothels, and hired the officers as doormen and muscle.

One defendant, Detective Rene Samaniego, was described by Mr. Chain as the worst offender. He gave Mr. Paz and brothel workers physical descriptions of undercover officers who were expected to visit the prostitutes, Mr. Chain said. Sometimes Mr. Samaniego relayed the descriptions from his station house, and other times, from outside the brothel, when he himself was part of an investigation.

“His conduct was egregious,” Mr. Chain said. “It is far beyond any of the other officers who are charged here today.”

Once, a prostitute was arrested and became the subject of a human trafficking investigation by the Queens district attorney’s office. Detective Samaniego told her employers at the brothel about the investigation, and her pimps told her what to say to prosecutors to deter them from pursuing the case, Mr. Chain said.

For his services, Detective Samaniego was paid regular weekly installments of $500, Mr. Chain said. While the corruption investigation was underway, the officers involved were making prostitution arrests in the course of their work; Detective Samaniego arrested a woman in 2017 after she offered sex for $100, he wrote in a criminal complaint.

The two officers who are brothers, Cliff Nieves, 37, and Steven Nieves, 32, were described as doormen for brothels. Officer Steven Nieves worked the door at a pop-up brothel and was videotaped accepting “large sums of cash,” said Christine Oliveri, an assistant district attorney. His brother set prices for sex with prostitutes at the same location, she said.

Later on Thursday, Mr. Paz pleaded not guilty, and he was being held on $325,000 cash bail. Prosecutors said Mr. Paz ran the operation with the help of his wife, Arelis Peralta, and stepdaughters, Jarelis Guzman and Arisbel Guzman, who live with the couple in Queens Village. All three women also pleaded not guilty Thursday. The women greeted clients at brothels and handled cash, smuggling some profits to the Dominican Republic, Mr. Chain said.

Ms. Peralta collapsed in tears as her daughters stood before the judge and pleaded not guilty. Court officers lifted her and carried her out of the courtroom.

The accused officers have a stack of wrongful-arrest and excessive force complaints and lawsuits over the years.

Arrests for prostitution have declined in recent years in the city, but it remains a stubborn problem in parts of Queens and Brooklyn. Arrest rates for prostitution offenses — including patronizing, promoting, compelling, permitting, loitering and sex trafficking — are higher in the two boroughs than elsewhere in the city.

The brothels in the case are on Jamaica, Liberty and Onderdonk Avenues in Queens; on Foster, Fourth and Gates Avenues and on 42nd Street in Brooklyn; and on Front Street in Hempstead, Long Island, prosecutors said.

One house that prosecutors said was used as a brothel on Onderdonk Avenue, a quiet residential street in Ridgewood, Queens. It sits across from a playground and on Thursday a sign in an upstairs window read, “Warning: Security Dog.”

“I thought those were rich people,” said Rick Jerry, 17.

Rory Lancman, a Queens councilman and candidate for district attorney, said one particularly surprising element of the scandal was the fact that one of the accused officers serves in the 109th Precinct in Flushing, which was the setting for a similar police protection case in 2015.

“How is it possible that a cop in the 1-0-9 would think they could engage in corruption after seeing their colleagues hauled off in handcuffs within the last couple of years?” Mr. Lancman said.

In his remarks on Thursday, Mr. O’Neill repeatedly referred to the case as an act of betrayal.

“These criminal activities involving people who raised their hands and swore an oath to stand up for ideals greater than themselves detracts from everything we’ve accomplished and validates those who harbor distrust of their police,” Mr. O’Neill said. “Although it’s a step backward, it’s an episode that our city and the N.Y.P.D. will rebound from together.”

A version of this article appears in print on , on Page A1 of the New York edition with the headline: Brothels and Betting: Charges Depict New York Police Crime Ring. Order Reprints | Today’s Paper | Subscribe