The man who shot dead two New York police officers told members of the public "watch what I'm going to do" shortly before the attack, police say.
Ismaaiyl Brinsley, 28, had a history of violence and mental instability.
Candlelit vigils have been held in New York in memory of the two officers, Liu Wenjin and Raphael Ramos, the BBC reports.
Brinsley shot them as they sat in their patrol car in Brooklyn before running into a nearby subway station and reportedly shooting himself.
Chief of Detectives Robert Boyce said Brinsley, 28, had "no history of radicalisation" but that he was "often violent" and had been arrested at least 19 times.
Brinsley had a troubled childhood and was so violent his mother was afraid of him, police said.
He had posted messages on social media saying he would kill police officers in retaliation for the death of Eric Garner, a black man who died when white police officers arrested him.
The killings come at a tense time, with nationwide protests over the deaths of unarmed black men at the hands of police officers.
The Rev Al Sharpton, a prominent civil rights activist, said Mr Garner's family had no connection to the gunman and called the killings "reprehensible".
Community leaders have called for peace and the mayor of New York, Bill de Blasio, has ordered flags across the city to be flown at half-mast.
"I hope and pray that we can reflect on this tragic loss...so that we can move forward and find an amicable path to a peaceful co-existence," Raphael Ramos' aunt, Lucy Ramos, said at one of the memorials being held across the city.
The attacks have also put pressure on the New York mayor.
Officers turned their back on him at a news conference, angry at what they saw as his support for protests against the police.