A former state narcotics agent who accidentally shot two strangers after a boozy night out on the Upper West Side took a plea deal Wednesday and was sentenced to 100 hours of community service.

Victor Zambrano, 50, had been drinking heavily at a bar near 82nd St and Amsterdam Ave when he stumbled into the street Sept 12 2014, he admitted in Manhattan court.

After he left the watering hole, he clumsily tried to unload his .40 caliber Glock and the weapon discharged twice, striking a 42 year-old man and a 31-year-old woman, he said.

Zambrano, who lost his job as an agent for the state Bureau of Narcotics Enforcement over the embarrassing mishap, pleaded guilty to two counts of misdemeanor assault. If he stays out of trouble for six months, he’ll dodge up to a year in jail.

Zambrano can no longer register for a gun license and must pay the victim’s medical expenses, authorities said.