Heroic Bronx police officer Brian Mulkeen was killed by friendly fire from his fellow cops — but maintained grasp on his service weapon to the bitter end of his struggle with an ex-con, the NYPD announced Monday.

“This is a tragic case of friendly fire,” Police Commissioner James O’Neill said during an afternoon press briefing. “But make no mistake we lost the life of a courageous public servant solely due to a violent criminal who put the lives of the police and all the people we serve in jeopardy.”

Mulkeen, 33, was shot twice amid his life-or-death struggle with reputed gangbanger Antonio Lavance Williams early Sunday in the borough’s Edenwald Houses, but it was initially unclear whether he was shot with his own service Glock, struck by rounds from other officers or both.

Now, investigators have concluded that he was only ever struck by friendly fire as he became the second cop shot dead in the line of duty this year — and the second by errant NYPD bullets.

Mulkeen and two fellow plainclothes anti-crime cops tamping down recent area gang tensions tried to chat up Williams around 12:30 a.m. Sunday, but he took off running behind a development building, loaded .32-caliber revolver in hand, police said.

Mulkeen, a former college track-and-field star, ran down, tackled and disarmed Williams — who made a desperate attempt to snatch Mulkeen’s Glock from his holster, according to cops.

As the pair battled for control of the gun, Mulkeen never lost his handle on it, squeezing off five rounds at Williams, officials said Monday.

“Mulkeen retained his firearm during the entire violent struggle he had with this suspect,” said O’Neill. “He fired five rounds at the suspect.”

It remains unclear whether any of those rounds struck Williams — but it’s now known none of them struck Mulkeen.

The shots from the Glock prompted five fellow cops on the perimeter to open fire into the fray, according to NYPD officials.

By Monday, the NYPD determined that Mulkeen’s partners fired off 10 shots — two of which struck their brother in blue in the head and torso — even though Mulkeen was wearing a bulletproof vest. The torso shot exited his body through his thigh, leading officials to first say Mulkeen had been shot three times.

When the guns fell silent, Williams, 27, was dead and Mulkeen lay dying.

The 15 shots rang out over only 10 chaotic seconds, according to O’Neill.

“It was a violent struggle and from start to finish, from first round to last round, was 10 seconds,” the commissioner said. “Just think about that. Think about how quick that is.”

Mulkeen was pronounced dead at Jacobi Medical Center.

“We lost another great NYPD police officer,” O’Neill said. “Brian Mulkeen truly had such a long and productive career ahead of him.”

O’Neill said the NYPD was working with the district attorney’s office to release footage of the incident from the five body-worn cameras.

Mulkeen’s camera was not among those recording, as he never had a chance to turn his on.

Queens cop Brian Simonsen, the other NYPD hero fatally shot in the line of duty this year, was also killed by friendly fire.