A retired NYPD detective fatally shot a would-be carjacker after the guy and a pal tried to rob him in Brooklyn early Tuesday, and later tearfully recounted his harrowing ordeal, saying, “I didn’t want to die,” authorities and the man said.

Former cop Derrick Bishop, 55, was working the graveyard security shift outside of a bottling facility in East New York before the thugs tried to rob him, the man and sources said.

Bishop said he was in his 2004 Mercedes sedan waiting for a truck delivery so he could open the gates when gunman Manuel Ocampo, 18, crept up to his car at the corner of Georgia Avenue and Linden Boulevard around 3:15 a.m. and stuck a .9mm pistol at his driver’s side window.

“I looked at him, and I see his hands and see he has a .9mm pointed at my face,” a shaken Bishop recalled, speaking to reporters outside his Brooklyn home. “Then he told me he’s going to blow my brains out, he would shoot me in the face if I didn’t hand him my money.”

Bishop rolled down the window and handed over what cash he had in his pockets, along with a few lottery tickets, but the thief ordered him to get out of the car and began digging through his pockets.

“He kept saying, ‘That’s all the f— you got? I’m gonna kill you, I’m gonna shoot you,’ ” Bishop said.

“So I started taking everything out of my pocket and throwing it on the ground, hoping he would look down at the ground because I was trying to get some type of advantage and it just didn’t look good.”

Ocampo then grabbed the former cop’s keys and hopped in the driver’s seat while still aiming the gun at Bishop as he tried to unlock the passenger’s side door for his nephew and alleged accomplice, Rashawn Thompson, also 18.

I thought I was gonna die in the car at that time. I didn’t want to die. I wanted to be able to see my kids and my wife. - Derrick Bishop

When the armed thief turned his gaze away from the 20-year NYPD vet, Bishop pulled out his legal Glock .9mm and blasted Ocampo four times in the chest and neck, he said.

“I thought I was gonna die in the car at that time,” Bishop said, wiping away tears. “I didn’t want to die. I wanted to be able to see my kids and my wife.”

Ocampo tried to run but quickly collapsed on Georgia Avenue, where officers found him clutching his gun. He later died at Brookdale Hospital.

Bishop said that one of the responding officers told him that Ocampo’s gun had jammed, preventing him from shooting Bishop.

“Believe me I feel blessed and lucky – you name it,” he said. “Whoever his name is up there, God, Jehovah, Buddha, whatever it is, I believe it.”

Meanwhile, Thompson ran to his home on nearby Cozine Avenue and told his mother that someone had shot at him before she dragged him back to the scene of the crime, where investigators took him into custody and is currently being questioned, sources said.

The ex-detective, who patrolled Crown Heights before retiring in 2003, was rushed to Kings County Hospital, where he was treated for an asthma attack.

Sources said surveillance video shows Ocampo and Thompson approaching the car and then running away after the shots were fired, but does not actually show the robbery and subsequent shooting.

“He’s a very conservative person. He’s very gentle and calm,” the manager of the bottling plant said of Bishop. “I know he was caught off guard.”

Police commissioner Bill Bratton said the gun Bishop used to kill Ocampo was legal.

Bishop is not expected to be charged with a crime, sources said.