A gunman has shot dead two police officers sitting inside a patrol car in New York before killing himself
The head of the New York police said the men had been “targeted for their uniform”.
The gunman ran into a nearby subway station where he then shot himself, officials say.
Earlier, the attacker shot and injured his ex-girlfriend and had posted anti-police messages on social media.
The mayor of New York, Bill de Blasio, said anyone who saw postings indicating a threat to the police should report them to the authorities. The “whole city was in mourning” after the shootings, he said.
The shootings come at a time when New York city police are facing intense scrutiny for their tactics, the BBC’s Samira Hussein reports from New York.
Earlier this month, a grand jury did not indict any New York police department officer in the chokehold death of Eric Garner, a black man who died when white police officers tried to arrest him for selling cigarettes.
The decision sparked protests in New York and other cities across the US.’Simply assassinated’
The officers were on duty in the Bedford-Stuyvesant area of Brooklyn when they were shot on Saturday afternoon.
Officers Liu Wenjin and Raphael Ramos were pronounced dead in hospital.
Bill Bratton, commissioner of the New York police department, said the officers had been shot with “no warning, no provocation – they were quite simply assassinated”.
The killer’s name was given as Ismaaiyl Brinsley, 28.
The gunman was a black man while the two police officers were Asian and Hispanic, police said.
Commissioner Bratton said the suspect had wounded his former girlfriend earlier on Saturday in Baltimore and had made posts from her Instagram account.
“This may be my final post,” said one that included an image of a silver handgun.
Two officials told the Associated Press news agency that the gunman had also posted about shooting police in retaliation for the death of Mr Garner.
US Attorney General Eric Holder called the shootings an “unspeakable act of barbarism”.
The Rev Al Sharpton, a prominent civil rights activist, said Mr Garner’s family had had no connection to the gunman and he denounced the violence.
“Any use of the names of Eric Garner and Michael Brown [a black man shot by a white police officer in Ferguson, Missouri] in connection with any violence or killing of police, is reprehensible and against the pursuit of justice in both cases,” Rev Sharpton said.
Deputy Inspector Michael Deddo, of Brooklyn’s 66th Precinct police,tweeted: “Our prayers are with our fellow NYPD brothers who were executed in the line of duty today in Brooklyn”.
The last fatal shooting of a New York police officer was in 2011.
The president of the police officers union in New York, the Patrolmen’s Benevolent Association, has spoken out angrily about the attack,
Patrick Lynch told the BBC’s News Channel that Mayor de Blasio should be held accountable for the deaths of the two officers.
“There’s blood on many hands tonight,” he said. “Those that incited violence on the street under the guise of protest. We tried to warn – it must not go on, it cannot be tolerated. That blood on the hands starts on the steps of city hall, in the office of the mayor.”