It was one of the worst police corruption scandals in New York City in recent years: a multilayered criminal operation that included brothels in Brooklyn and a numbers racket run out of beauty salons and a deli in Queens.

It took in millions of dollars. And it was all masterminded, investigators said, by a retired police detective who recruited at least seven police officers. One was his former partner. Two others were brothers who have been accused of holding a bachelor party in a brothel.

On Tuesday , the former detective, Ludwig Paz, 51, pleaded guilty to two counts of attempted enterprise corruption and one count of promoting prostitution. He also agreed to forfeit $20,840 in illegal profits. He is scheduled to be sentenced on June 27 by Justice Ronald D. Hollie in State Supreme Court in Queens. He could face up to 12 years in prison.