NEW YORK — An armed man walked up to two New York Police Department officers sitting inside a patrol car and opened fire Saturday afternoon, killing one and critically injuring a second before running into a nearby subway station and committing suicide, police said.

The shooting took place in Brooklyn's Bedford-Stuyvesant neighborhood. Both officers were rushed to Woodhull hospital, where one was pronounced dead. Police had said at least one of the officers was shot in the head.

Authorities say the suspect fatally shot himself inside the station. His motive wasn't immediately clear.

A block from the shooting site, a line of about eight police officers stood with a German shepherd blocking the taped-off street. Streets were blocked even to pedestrians for blocks around.

Derrick Thompson, who lives nearby, said the shooting happened across from the Tompkins Houses public housing development.

"I was watching TV, and then I heard the helicopters," Thompson said. "I walked out, and all of a sudden — this."

The shooting comes at a time when police in New York and nationwide are being heavily criticized for their tactics following the chokehold death of Eric Garner, a black man who was stopped by police for selling loose, untaxed cigarettes and could be heard on an amateur video gasping, "I can't breathe" as he was being arrested.

Demonstrators around the country have staged die-ins and other protests since a grand jury decided Dec. 3 not to indict the officer involved in Garner's death, a decision that closely followed a Missouri grand jury's decision not to indict a white officer in the fatal shooting of Michael Brown, an unarmed black 18-year-old.

Several New York officers were assaulted during demonstrations that have largely been peaceful, including one that drew thousands to the Brooklyn Bridge.

The president of the police officers union, Patrick Lynch, and Mayor Bill de Blasio have been locked in a public battle over treatment of officers following the decision not to indict the officer in Garner's death. Just days ago, Lynch suggested police officers sign a petition that demanded the mayor not attend their funerals should they die on the job.

The last shooting death of an NYPD officer came in December 2011, when 22-year veteran Peter Figoski responded to a report of a break-in at a Brooklyn apartment. He was shot in the face and killed by one of the suspects hiding in a side room when officers arrived. The triggerman, Lamont Pride, was convicted of murder and sentenced in 2013 to 45 years to life in prison.