The slain officers were identified as Wenjin Liu, a seven-year veteran of the NYPD, and Raphael Ramos, who joined the force two years ago.
The 28-year-old gunman was identified as Ismaaiyl Brinsley, a black man, who had driven over 300 km from Baltimore. Authorities said he had written in social media posts that he planned to kill police officers in the wake of the deaths of two blacks, Eric Garner and Michael Brown, by police officers.
"Our city is in mourning. Our hearts are heavy," he said at a press conference on yesterday's killings.
"Our entire city was attacked by this heinous individual," the mayor said.
Also Read
New York Police Commissioner William Bratton said Ramos and Liu were among New York's "finest" police officers and "were shot and killed with no warning or provocation while they were sitting in their police car in Brooklyn.
"While sitting in a marked police car, both were ambushed and murdered. Both officers paid the ultimate sacrifice today while protecting the communities they served," Bratton said.
He shot through the passenger side window on the officers' heads and upper bodies in an attack so sudden that the officers could not even draw their weapons.
He then ran to a nearby subway station and committed suicide by shooting himself as officers closed in.
A semi-automatic handgun was recovered at the scene.
"Officer Ramos and Officer Liu never had the opportunity to draw their weapons," Bratton said, adding that "They may never have had the chance to see their murderer."
An online posting suggested a link between Brinsley, who was black, and anger over the death of Garner.
The account, using the slang insult pig for police, said: "I'm Putting Wings On Pigs Today. They Take 1 Of Ours ... Let's Take 2 of Theirs."
#ShootThePolice #RIPErivGardner (sic) #RIPMikeBrown This May Be My Final Post. I'm Putting Pigs In A Blanket," (sic).
The shooting of the police officers comes days after protests had erupted across the US over the deaths by black men Garner and Brown at the hands of the police.