A drunk off-duty state narc turned the Upper West Side into a shooting gallery Friday night, blasting a woman and her boyfriend in a struggle over his gun after the three spent a boozy night together in a bar, police sources said.

Victor Zambrano Jr., 49, handed his firearm to the 31-year-old woman when she asked to hold it as they all stood on West 82nd Street and Amsterdam Avenue — then tried to grab it back at about 9 p.m., cops say.

The gun went off as the state Bureau of Narcotics Enforcement agent and the woman fought over it, sources said.

The bullet ricocheted off the street. First it struck her foot, then slammed into her 42-year-old boyfriend’s shin.

The boyfriend limped after the fleeing cop up Amsterdam until the narc spun around at 83rd Street and tried to shoot him — but his gun misfired, according to the sources.

Zambrano — who lives near the incident — is being charged with assault, criminal possession of a weapon, resisting arrest and reckless endangerment, police say.

“We heard like a pop first, and then we saw cops outside with their guns drawn,” said Carolyn Frankel, who was in a local pub when the shots rang out.

“Everybody just started running towards the middle of the bar and getting down on the ground. You’re just thinking of a stray bullet, and you don’t want that anywhere near you.”

A manager at Organic Avenue on 82nd Street told The Post he gave the female victim water and wrapped paper towels around her foot.

“He ankle was bleeding,” he said. “She was calm and in shock. She was not crying. She said she was just going out to dinner with her boyfriend and heard a pop and realized she was bleeding.”

Police disarmed and collared Zambrano at the scene.

The victims, who were being treated at St. Luke’s Hospital, did not suffer life-threatening injuries.

Police found the gun on the ground near 83rd Street, a source said.

A 2008 report on misconduct within the narcotics bureau said Zambrano was issued 11 summonses worth $1,015 for improper parking of his vehicle with state-issued placards.

According to the state Inspector General probe, Zambrano’s tickets were unpaid when the report was issued even though the IG informed him of the outstanding summonses.

Additional reporting by Josh Saul, Matt McNulty and Gabrielle Fonrouge.