A 20-year-old man was shot by police after officials say he tried to rob a detective in Brooklyn.

It happened Sunday night at the intersection of Monroe Street and Bedford Avenue.

Cops say the detective was waiting to make an arrest when the suspect tried to rob him with a BB gun.

"The detective was robbed of his cellphone," said NYPD Chief of Detectives Robert Boyce. "As he hands over the cellphone he then produces a handgun and fires one round striking the perpetrator. We have statements from two people arrested at that scene who acknowledge they're a part of a robbery team. Who, actually we have a robbery pattern on them that they admit to, so that's where we stand right now."

The suspect was shot twice and is listed in stable condition at the hospital. A 16-year-old boy was taken into custody.

The gun was recovered at the scene.

Police are also looking for a third suspect, between 16 and 18 years old, who was wearing a grey hoodie and blue jeans.

Police believe they've all been involved in four armed robberies since late September.

Anyone with information about the case is asked to call Crimestoppers by calling 1-800-577-TIPS, by texting TIP577 to CRIMES, or by going to NYPDCrimeStoppers.com.