Michael Verbitsky, 19, told cops he was pointing the Walmart-purchased pellet rifle at Carl Schurz Park across from a 10th-floor apartment at 170 East End Ave.

He insisted he was just “f–king around with the gun” when he accidentally fired the pellet that struck a plainclothes detective in the back as she was getting out of an unmarked car with her partner at 7:15 p.m. Sunday, the sources said.

Hearing a pop, the cops looked up, noticing a pair of moving curtains and a silhouette in an open window, the sources said.

With the help of a doorman, they located the apartment — but Verbitsky and his 18-year-old girlfriend, Gabrielle Gleyberman, told the officers they couldn’t enter without a search warrant, the sources said.

When the cops went downstairs, Verbitsky and his gal pal allegedly attempted to sneak out through the basement, but officers apprehended them outside.

Cops found the air gun hidden in a drop ceiling in the 4,400-square-foot apartment, where Verbitsky was staying while his parents were in the Hamptons, sources said.

He was hauled into Manhattan Criminal Court Monday night after a day behind bars, and was hit with a slew of charges, including assault, criminal possession of a weapon, criminal mischief and reckless endangerment.

Investigators at the scene of the BB gun shooting on Sunday night.Demetrius Loadholt

The criminal-mischief charges were related to two prior incidents when residents on East End Avenue said their windows were shattered by gun pellets.

Verbitsky was also hit with two charges of criminal possession of a forged instrument for two fake New Jersey driver’s licenses cop said they found in the apartment.

He was sprung on $10,000 bail.

Cops are continuing to investigate the role of the girlfriend, who claims she was sleeping when the gun popped off.

De Blasio wasn’t at Gracie Mansion during the incident.

Verbitsky has six prior arrests on charges including petit larceny, criminal possession of a controlled substance and robbery, sources said.

And the teen may have used other victims as target practice. A Con Ed worker came forward on Monday, telling cops he’d been hit by what he thought was a pellet while working in front of the building on Aug. 10.