A wild shootout in an upper Manhattan parking lot Thursday afternoon left a cop with a bullet in his arm, and his assailant — a Trinitarios gangbanger — dead, police and sources said.

A video-surveillance camera at the lot caught dramatic footage of the suspect exchanging gunfire with the NYPD officer, a member of the 34th Precinct’s Anti-Crime Unit.

The plainclothes officer, identified by sources as Justin Vartanian, was responding to a call of a man bizarrely firing a gun at the lot at Broadway and 187th Street in Washington Heights at about 4:30 p.m., according to police.

“Someone is shooting in the air!” reported a 911 caller.

Officials said Vartanian came upon the suspect and tried to take him into custody.

The suspect, a member of the deadly Trinitarios gang, attempted to flee — turning around multiple times and firing at officers who showed up at the scene, police sources said.

“[The suspect] runs with a gun in his hands, and an officer pursues on foot leading to a parking garage on Broadway,” Commissioner James O’Neill said at a press briefing.

“The suspect then runs to the rear of the parking lot and takes the position behind the last parked car. Our officer takes cover behind a vehicle three cars away. The suspect then fires three rounds. The police officer was struck in the right armpit. The wounded officer fires back one time.”

The suspect was shot once in the chest and was pronounced dead at NewYork-Presbyterian/Columbia hospital at 5:10 p.m.

Vartanian, meanwhile, was recovering at Mount Sinai St. Luke’s Hospital Thursday night in stable condition.

During the shootout, one round pierced the windshield of an unmarked police car.

“We saw today from the video we observed a very, very dangerous situation unfold, and our ­officers handled it with extraordinary professionalism and courage,” said Mayor Bill de Blasio.

“Here we are talking about broad daylight, something happening out of nowhere. These officers did everything right.”

Additional reporting by Craig McCarthy, Shari Logan and CJ Sullivan