An NYPD detective was arrested Sunday for fondling himself in front of the windows of Long Island homes, police sources said.

Detective Robert Francis was arrested after one homeowner in Rockville Centre called 911 to report that a man was standing in the back yard masturbating, the sources said.

Francis allegedly entered the back yards of more than one home and shined a flashlight inside until he got someone’s attention. Then, as the person was looking at him, Francis shined the light on himself to show he was fondling himself, the sources said.

Police arrested Francis around 2:30 a.m. and charged him with public lewdness, endangering the welfare of a child and trespassing. It was not clear how many homes he allegedly targeted.