The suspected gunman was also wounded.
Police Commissioner Ray Kelly says officer Ricardo Ramirez was on patrol with two others when they spotted a young man riding a bike on the sidewalk. They stopped to question him, and he took off and ran.
The officers followed and cornered the suspect, and that's when police say he started firing at them.
"If officer Ramirez and his team had not confronted the suspect, the shooter would still be on the street, and he may have killed innocent New Yorkers," Mayor Michael Bloomberg said.
Ramirez, a 4-year veteran, got a special visit from Bloomberg at Kings County Hospital Sunday night. The mayor says the 29-year-old is expected to make a full recovery after suffering two bullet wounds to his leg. A third bullet struck Ramirez' bullet-resistant vest, which may have saved his life.
The officer suffered his injuries, police say, while chasing down 17-year-old Elijah Foster-Bey inside a building on Bradford Street in East New York.
Ramirez was with two other plain-clothes officers when they say the suspect opened fire in a stairwell.
"When he got up to the top landing, he apparently couldn't open the door," Kelly said. "He turned and started to fire at the officers."
Police say they returned fire with 11 shots, hitting Foster-Bey three times. He was taken to Brookdale Hospital and is expected to survive his injuries. Foster-Bey is charged with attempted murder of a police officer and criminal use of a weapon. Additionally, police say Foster-Bey's mother had filed an order of protection against him.
The suspect's gun was recovered at the scene. Kelly said the weapon could hold seven rounds, but that only one bullet was left in the chamber.
The NYPD had increased presence in area in response to pattern of bike robberies. It is not known if Bey was involved in that bicycle robbery pattern.
In one robbery, the suspect is described as possessing a black gun.
Additionally, there were four recent shootings in vicinity of Bradford Street in East New York that police were investigating.