The man who murdered two New York City police officers posted deadly internet threats hours before he ambushed them in their patrol car, it has emerged.

William Bratton said the officers, Liu Wenjin and Raphael Ramos, were "quite simply assassinated", shot in the head without warning, after the gunman approached the passenger window of a marked police car in Brooklyn's Bedford-Stuyvesant neighbourhood and opened fire.

The suspect, Ismaaiyl Brinsley, 28, then ran inside a Brooklyn underground station, where he killed himself.

Mr Bratton said Brinsley shot and wounded his ex-girlfriend earlier in Baltimore and made posts from her Instagram account. "This may be my final post," said one that included an image of a silver handgun.

He also posted about shooting two "pigs" in retaliation for the death of Eric Garner, an unarmed black man who was stopped by police on suspicion of selling loose, untaxed cigarettes and put in a chokehold. Brinsley was black and the officers were Asian and Hispanic, police said.

"I'm putting wings on pigs today. They take 1 of ours, let's take 2 of theirs," Brinsley posted, using the hashtags Shootthepolice RIPErivGardner (sic) RIPMikeBrown.

The shooting happened hours later, around the time that Mr Bratton said New York police were receiving a warning fax from Baltimore authorities.

US attorney general Eric Holder called the shooting deaths an "unspeakable act of barbarism" and Barack Obama said there was no justification for the killings.

The president said police officers risked their own safety to serve and protect their communities and deserved the public's respect and gratitude.

He urged Americans to reject violence and harmful words and to instead embrace words that heal, and to seek out prayer and sympathy for the victims' relatives.

Police in New York are being criticised for their tactics following the death of Mr Garner. Amateur video captured an officer wrapping his arm around Mr Garner's neck and wrestling him to the ground. Mr Garner was heard gasping "I can't breathe" before he lost consciousness.

Demonstrators around the US have staged protests since a grand jury decided on December 3 not to charge the officer involved. The decision closely followed a Missouri grand jury's decision not to indict a white officer over the fatal shooting of unarmed black teenager Michael Brown, 18.

The family of Mr Brown condemned the shooting of the New York City officers.

The statement released by Parks & Crump law firm said Mr Brown's family rejected "any kind of violence directed toward members of law enforcement. It cannot be tolerated".

It called on citizens to "work together to bring peace to our communities" and said: "Our thoughts and prayers go out to the officers' families during this incredibly difficult time."

Mr Bratton said police were looking at whether Brisley had attended any rallies or demonstrations.

Civil rights activist the Rev Al Sharpton said Mr Garner's family had no connection to the suspect and condemned the violence.

"Any use of the names of Eric Garner and Michael Brown in connection with any violence or killing of police is reprehensible and against the pursuit of justice in both cases," he said.

The last shooting death of a New York Police Department officer came in December 2011, after a report of a break-in at a Brooklyn apartment.

Criminal records show Brinsley had a history of arrests in Georgia for offences including robbery, shoplifting, carrying a concealed weapon, disorderly conduct and obstruction of a law enforcement officer.

Mr Bratton said his last known address was Georgia, but he had some ties in Brooklyn.

Sign up to our free newsletters

Get the best updates straight to your inbox:
Please select at least one mailing list.

You can unsubscribe at any time by clicking the link in the footer of our emails. We use Mailchimp as our marketing platform. By subscribing, you acknowledge that your information will be transferred to Mailchimp for processing.