Police believe the NYPD officer shot Tuesday night in Brooklyn was wounded by friendly fire, authorities said in a late night news conference.

Police had two suspects in custody and sought a third Tuesday night after the shooting.

The incident came after an NYPD sergeant and detective, dressed in plain clothes, approached a vehicle where they believed a heroin deal was taking place and identified themelves as officers, police officials said.

Shots rang out when the car's driver, a 45-year-old man with 58 prior arrests, tried to pull away while the detective was leaning inside the passenger-side window attempting to make an arrest, police said. 

RELATED: Watch a dog-walker open fire on Harlem Street

But it was the detective's fellow officer who shot him, with a bullet landing in his shoulder in the crossfire, police said, adding that both officers fired four shots total.

The vehicle's driver was also shot, police said. He sustained injuries to his leg and wrist.

Also in the car was a 51-year-old man with 17 prior arrests. He was not injured, police said. Both suspects are in custody.

A third suspect fled on foot, police said.

The shooting happened near Troutman Street and Wilson Avenue in Bushwick, according to police.

The cop was taken to Elmhurst Hospital, NYPD spokesman Carlos Nieves tweeted Tuesday night. The officer is in "stable condition" and is "conscious, alert and talking" according to Nieves.

RELATED: Sketch released of man who pushed teen onto subway tracks in Queens

"I’m thankful that the detective is stable, awake, and alert, and, all things considered, in good spirits,"  First Deputy Commissioner Benjamin B. Tucker said in remarks made at the hospital. 

Mayor Bill de Blasio left Boston Tuesday night en route to the Queens hospital, according to reporting from NBC. He was reportedly there attending funeral services for the father of NYPD Commissioner Bill Bratton.

“Tonight’s shooting is an important reminder of the critical and dangerous work our police department does each day," Mayor de Blasio was quoted in a statement. "We’re grateful the detective is doing well, and we wish him a safe and swift recovery."

The incident marks the sixth time since January an NYPD officer has been shot in the line of duty.