NEW YORK  — A New York City police officer was shot to death early Wednesday morning, ambushed in a marked patrol car by a man with a revolver who was later killed by officers.

Officer Miosotis Familia, a 12-year member of the department, was assigned with a partner to a mobile command post when the man fired one round through the window and struck her in the head as she was wrapping up her shift. She was rushed to a hospital but did not survive.

"This was an unprovoked direct attack on police officers who were assigned to keep the people of this city safe," Police Commissioner James O'Neill said.

Her partner radioed for help, and officers responded fast, encountering the suspect, 34-year-old Alexander Bonds, about a block away, he said. As they confronted him, he pulled a revolver, and police fired, striking and killing him. A silver revolver was found at the scene. A bystander was hit in the stomach by a bullet during the standoff, and is in stable condition, police said.

Bonds had been on parole for a robbery case in Syracuse, New York, police said. He is seen in surveillance footage marching up to the post "with purpose," officials said, but it's not clear what provoked the attack.

The shooting recalled the Dec. 20, 2014 killing of patrol officers Wenjian Liu and Rafael Ramos, who were ambushed and shot to death in their vehicle without warning by a man who approached the passenger window of their marked police car. The suspect, 28-year-old Ismaaiyl Brinsley, then fatally shot himself. Brinsley announced online in the moments before the shooting that he was planning to shoot two "pigs" in retaliation for the police chokehold death of Eric Garner.

Witness Jay Marzelli told the Daily News of New York he thought the shots Wednesday were fireworks at first.

"I was in this bodega right here on Creston, just getting a sandwich and all of a sudden there was all this running and stuff going on, and I look out probably 40, 50, 60 cops screaming, 'Call a paramedic, clear the block!'" he said. "It looked like there was a riot going on, and two seconds later I hear gunshots, 'Bam, bam,' and then the police officer was just laying there."

(Copyright 2017 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed)

More From New Jersey 101.5 FM