A no-nonsense Manhattan judge is freeing New Yorkers from a gross commute — one dangerous, lewd rider at a time.

Saying New Yorkers shouldn’t have to face “public masturbators” on the subway, Judge Ann Scherzer tossed a retired NYPD detective in prison for a year for pleasuring himself in front of a woman and then pulling a gun on her and a fellow rider who tried to record the vile act.

Scherzer told ex-cop Steven Esposito, 57, that straphangers deserve “to be free of public masturbators and to be free of former police officers just taking out a gun and pointing it at innocent people because they’re upset they got caught.”

Defense lawyers urged the judge to give Esposito no jail time, arguing that he lost his wife in 2009 and that the crime was “an illicit expression of pent-up sexual desire.”

“Put yourself in this man’s shoes,” attorney Marc Fernich said in Manhattan Criminal Court.

“I cannot,” Scherzer interrupted.

The lawyer persisted, adding that Esposito simply became “flustered and spontaneously panicked in the heat of the moment” when he pulled out his firearm on the victim and a good Samaritan who came to her aid at the 59th Street Station.

“I’m very sorry for him” said Scherzer, dryly. “But I would have hoped that he would have found a way to tend to his sexual needs other than masturbating on a subway platform, staring at a young woman while making hissing sounds.”

A jury convicted Esposito in December of menacing, exposure and public lewdness.

The judge’s sentence was the maximum — and far greater than the 45 days in jail that prosecutor Bernard Eyth requested.

Fernich, who recently came onto the case, asked the judge to toss the convictions because he claimed that his trial lawyer had failed to inform him he faced jail time in the case.

“This is a detective who has served with the NYPD for 20 years — he obviously knows how this works,” the judge shot back.

After Scherzer meted out the hefty punishment, Esposito was cuffed and hauled out of the courtroom.

The judge said she was particularly moved by the victim’s testimony at trial.

The woman told jurors that she was terrified when she saw Esposito “playing with his penis” on the subway platform around midnight.

“He was looking at my face, and smiling, and making sexual noises, like he was going to force me to ,” the woman, trembling, told jurors.

Our editors found this article on this site using Google and regenerated it for our readers.