Two NYPD officers were shot and killed at about 2:45 p.m. on Dec. 20, 2014. View Full Caption

BEDFORD-STUYVESANT — Two police officers were killed in an "ambush" as they sat in a police vehicle Saturday afternoon by a gunman who bragged on Instagram about plans to kill police, Police Commissioner Bill Bratton said.

"Today two of New York's Finest were shot and killed with no warning," Bratton said.

Mayor Bill de Blasio and Bratton described their deaths as an "assassination."

After the shooting, gunman Ismaaiyl Brinsley, 28, then entered the nearby Myrtle-Willoughby G train subway station where he fatally shot himself, Bratton said.

Early Saturday morning, Brinsley shot his ex-girlfriend in Maryland, Bratton said. A warning from Baltimore-area police was faxed to the NYPD, but arrived too late.

NYPD Forms Honor Guard to Salute Slain Officers View Full Caption DNAinfo/Katie Honan

"The tragedy here is just that the warning was coming in the murder was occurring," Bratton said.

Officers Wenjian Liu, 32, and Rafael Ramos, 40, were sitting in a Critical Response Vehicle having taken part in a patrol exercise in 79th Precinct and were parked near Myrtle and Tompkins avenues at about 2:45 p.m. when Brinsley walked up and shot them both at close range, Bratton said.

Brinsley approached from the passenger side, where Liu was sitting, with Ramos in the driver's seat, took a shooting stance, and fired through the passenger window, striking both officers in the head, Bratton said.

"They may never have actually seen their assailant, their murderer," Bratton said.

Liu and Ramos both worked in the 84th Precinct, and were taken to Woodhull Medical Center, according to the NYPD, but were later pronounced dead.

"Our city is in mourning. Our hearts are heavy," de Blasio said. "We lost two good men who devoted their lives to protecting all of us."

Brinsley was taken to Brooklyn Hospital.

At 5:45 a.m. Saturday, Brinsley shot and wounded his ex-girlfriend in Baltimore County, MD, Bratton said.

Brinsley then posted threats against the police on both his and his ex-girlfriend's Instagram accounts, sources said.

He said he was going to "put wings on pigs today," in a post that earned at least 140 likes.

He also used hashtags referencing the deaths of Eric Garner and Michael Brown, who were both killed by police.

"They take 1 of ours," the post continued. "Let's take 2 of theirs."

The woman's mother notified Baltimore authorities that she saw the social media rants, police said.

Baltimore police then sent a fax that arrived as the officers were being ambushed, Bratton said.

More than a hundred emotional police officers lined the street as the two men's bodies were taken from Woodhull Medical Center just after 9:30 p.m.

Afterwards, the head of the city's largest police union blamed de Blasio and recent anti-NYPD protests for the shooting.

"There's blood on many hands tonight," Patrolmen's Benevolent Association President Pat Lynch said. "That blood on the hands starts on the steps of City Hall, in the office of the mayor."

Rev. Al Sharpton said in a statement that he had spoken to the Garner family and that they were "outraged" the gunman had invoked the Staten Island man's name.

"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," Sharpton said.

Baltimore County police said on Facebook that Brinsley is the suspect in the shooting of a woman in Owings Mills, MD.

They tracked him to New York City by his cell phone, sources said. Brinsley may have had a connection to East Flatbush, Bratton said.

Ramos and Liu were part of a special program to increase police presence in Police Service Area 3, which patrols nearby public housing complexes, said City Councilman Robert Cornegy, who represents the area.

"They were just a presence, they weren't over-policing," he said. "They were here as a presence to make the community feel safer."

Officer Liu, who had been on the force seven years, was married just two months ago, Bratton said.

Officer Ramos, who was also married and had a 13-year-old son, had been on the force for nearly three years, Bratton said, adding that he had been a school safety agent from 2009-2012.

Cassandra Harrell, 52, lives nearby and said she was "hoping and praying" that the shooting had nothing to do with the recent decision not to indict a police officer in the death of Eric Garner.

"I'm very worried there's going to be a backlash because of this horrible crime committed against the police," she said.

"This sets us back 1000 percent. I don't even know how you come back from this," Cornegy said. "If you wanted to articulate what the worst case scenario could be at a time when the city is trying to get back on track with police and community relations, this is it."