A gunman who announced online that he was planning to shoot two ‘‘pigs’’ in retaliation for the police chokehold death of Eric Garner ambushed two officers in a patrol car and shot them to death in broad daylight Saturday before running to a subway station and killing himself, authorities said.

The suspect, 28-year-old Ismaaiyl Brinsley, wrote on an Instagram account: ‘‘I'm putting wings on pigs today. They take 1 of ours, let’s take 2 of theirs,’’ officials said. He used the hashtags Shootthepolice RIPErivGardner (sic) RIPMikeBrown.

Police said he approached the passenger window of a marked police car and opened fire, striking Officers Rafael Ramos and Wenjian Liu in the head. The New York Police Department officers were on special patrol doing crime reduction work in the Bedford-Stuyvesant section of Brooklyn.

‘‘They were, quite simply, assassinated — targeted for their uniform,’’ said Police Commissioner William Bratton, who looked pale and shaken at a hospital news conference.

Brinsley took off running as officers pursued him down to a nearby subway station, where he shot himself in the head. A silver handgun was recovered at the scene, Bratton said.