An off-duty NYPD officer shot an armed and reportedly drunk man in the chest during an attempted carjacking in Brooklyn on Wednesday, police said.

The 28-year-old assailant approached the off-duty cop at around 2 a.m. in Canarsie, knocking on his window before firing a shot that "barely missed" the officer, according to Chief of Detectives Rodney Harrison.

"Our member of the service then pulled out his firearm, shooting several times at our perpetrator, striking him in the chest," Harrison told reporters.

Police sources who spoke to NBC 4 said the man had previously fired a revolver while drunkenly chasing people in a nearby bar parking lot. He also reportedly wrapped a gun in a condom, sticking it in his rectum to avoid detection by bar security.

The NYPD shard a photo of the plastic-wrapped gun covered in what appears to be blood, along with another firearm that they said was recovered at the scene.

Sources told the Post that the gun was wrapped in a bloody glove before it was placed in his butt.

The unidentified suspect was hospitalized with life-threatening injuries. The officer was not shot, but taken to a different hospital to be evaluated for tinnitus.

We'll update as more information becomes available.