A Los Angeles Superior Court judge just ruled that the Long Beach Police Department discriminated against gay men by ensnaring them in a homophobic sex sting operation.

Rory Moroney filed a lawsuit against the police department after he was charged with lewd conduct and indecent exposure in October 2014 when an undercover male officer lured him into the restroom at a public park then coaxed him into masturbating, only to arrest him as soon as he did.

Related: Long Beach Police Accused Of Illegally Targeting Gay Man In Bathroom Sex Sting

Moroney pleaded not guilty to the charges, which, if he were convicted, could have landed him on the sex offender for the rest of his life. Then he hired Bruce Nickerson, also known as the Gloria Allred of lewd conduct cases and police sting operations targeting gay men, to represent him in court. And it looks like that was a wise move, because Judge Halim Dhanidina invalidated Moroney’s arrest on Friday, ruling that the LBPD’s tactics were “tantamount to discrimination” and “indicative of animus toward homosexuals.”

“The presence and tactics of the decoy officers actually caused the crimes to occur,” Dhanidina said.

Prosecutors had tried arguing that the LBPD had based its policing tactics on citizen complaints about lewd conduct in men’s public restrooms, but Dhanidin was not convinced. In his ruling, he said the department failed to provide any evidence of such complaints and that officers had “intentionally targeted men who engaged in homosexual sex” simply because they were homosexual.

Related: Sexy Gladiator Sues The City Of San Diego For Arresting Him For Being “Too Sexy”

In a statement, the LBPD called the ruling “unexpected,” but promised to evaluate how it responds to complaints of lewd conduct in the future.

“We are 100 percent committed to civil rights and equality for all people, including the LGBTQ community,” Police Chief Robert Luna said. “Our department has many openly gay and lesbian employees who are a critical part of our team.”

After the ruling, Nickerson told press the case “should send a message to police in the rest of California not to do these kinds of ridiculous, silly, sting operations.”

As for Moroney, he’s just glad to have the whole thing behind him. As he left the courthouse Friday, he told reporters: “It was really hard to come out and be the voice, but I had to do it because I believe that Long Beach is discriminating against gay men.”

Related: Most Warm Sands Sex Sting Defendants Will Plead Guilty (But Avoid Sex Offender Scarlet Letter)

h/t: LA Times