The man who shot dead two New York police officers told members of the public to "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 officers Wenjian Liu, 32, and Rafael Ramos, 40.
Brinsley shot them as they sat in their patrol car in Brooklyn on Saturday before running into a subway station and shooting himself.
Hours earlier, he had shot and wounded his 29-year-old ex-girlfriend, Shaneka Thompson, at her home in Baltimore, Maryland, police said.
The New York Police Department's Chief of Detectives, Robert Boyce, said that for weeks before the shooting, Brinsley had posted anti-police and anti-government messages on his Instagram account referring to the deaths of Michael Brown and Eric Garner.
Protests erupted across the US last month after grand juries in Missouri and then New York declined to charge the white police officers who killed the two unarmed black men.
Chief Boyce said Brinsley had also shared his feelings of "self-despair and anger at himself and where his life was" in recent posts.
When he arrived in New York on Saturday - hours after shooting Ms Thompson in the stomach - Brinsley threatened on Instagram to kill police officers.
"They Take 1 of Ours... Let's Take 2 of Theirs #ShootThePolice #RIPEricGarner #RIPMike Brown," he continued before adding: "This May Be My Final Post."
Minutes before the attack, Brinsley struck up a conversation with two men, Chief Boyce said.
"He asked them for their gang affiliation; he asked them to follow him on Instagram; and then he says: 'Watch what I'm going to do.'"
He then walked past the patrol car with officers Liu and Ramos inside, circled it and, crossed the street and came up behind the car, Chief Boyce said.
He walked along the pavement before firing four bullets through the front passenger window, hitting both officers, and then ran.
Brinsley fled to a nearby subway station, where police said he shot himself in the head using his semi-automatic handgun.
Police departments in New York and several other cities were said to be operating on "high alert", fearful of copy-cat attacks.
The NYPD has suspended all auxiliary patrols for the time being, and police unions have told officers to respond to every radio call with two cars and to not make arrests "unless absolutely necessary", according to CBS News.
Forces are also monitoring social media for threats. In Memphis, Tennessee, a man was taken into custody after writing in a post that he was "driving to New York to kill more cops".
Meanwhile, the family of officer Ramos joined community leaders near their home in Brooklyn for a prayer vigil on Sunday.
His 13-year-old son, Jaden, wrote on Facebook: "It's horrible that someone gets shot dead just for being a police officer. Everyone says they hate cops but they are the people that they call for help."
Officer Ramos's cousin, Ronnie Gonzalez, said the family had already forgiven his killer.
Mr Gonzalez also said the family would not object to New York Mayor Bill de Blasio attending the funeral, adding: "We're not disrespectful. We're not going to throw him out and say: 'Don't be here.'"
The mayor has been criticised by unions over what they perceive as his lack of support and respect for the police amid the recent protests over the deaths of Mr Brown and Mr Garner.
Last week, the Patrolmen's Benevolent Association asked officers to sign a petition calling for Mr de Blasio to be barred from attending their funerals if they were killed in the line of duty.
And on Saturday night, several officers turned their back on Mr de Blasio as he entered a news conference about the shooting.