An NYPD detective is recovering in the hospital after being shot while trying to arrest two people in Brooklyn Tuesday night.

It happened during a buy-and-bust operation at Wilson Avenue and Troutman Street in Bushwick. 

The officer, identified by sources as Detective Jon Gladstone, and a sergeant went up to a car with two people who police say were selling drugs.

The driver reversed, crashed into a police car, then drove forward with the detective hanging out of the car.

The two officers opened fire.

The driver, who sources say is Oscar Vera, 37, was hit in the leg and wrist.

Gladstone was hit in the shoulder, and police are trying to figure out if it was friendly fire.

NY1 was the only television camera to meet Mayor Bill de Blasio when he visited the detective at Elmhurst Hospital. 

"He's a brave guy, and a really humble guy. He really minimized  what he went through, and I told him, 'No this is something you did that really protected people and particularly protected vulnerable young people'. Because he was getting heroin off the street. We all know what heroin's doing in our communities," De Blasio said.

One local resident says the extra police presence has made a difference.

"Cops have made a lot of progress cause it used to be a real bad neighborhood, but we have new people moving in so they gotta patrol a little more often," said the Bushwick resident.

Vera is being treated at Bellevue Hospital.

The passenger was taken into police custody, identified by sources as Geraldo Rodrigues, 51.

Police say the two suspects captured have extensive records with the driver having 68 prior arrests, and the passenger 17.

This was the sixth shooting of an NYPD officer so far this year.

Police are still looking for a third person who was outside the car and fled the scene.

Anyone with information on the case should contact the Crime Stoppers hotline at 1-800-577-TIPS, or text CRIMES and then enter TIP577, or visit www.nypdcrimestoppers.com.