NEW YORK - At the start of her midnight shift, Officer Miosotis Familia was in a New York Police Department mobile command post, writing in her notebook, when a gunman strode toward her.

She never saw Alexander Bonds coming before he shot her in the head through the passenger-side window, killing her before officers ultimately killed him, police said.

Police are investigating what may have prompted Wednesday's shooting, which Police Commissioner James O'Neill described as an officer being "assassinated in an unprovoked attack on cops."

"Officer Familia was murdered for her uniform and for the responsibility she embraced," O'Neill said in a message to officers Wednesday night. "For the NYPD, regularly achieving lower and lower crime figures means absolutely nothing when one of our own is brutally shot and killed."

A 12-year NYPD veteran, the 48-year-old Familia had come to police work later in life than most on a force where the average recruit is 26. She had been a nurse and medical assistant first, according to her profile on the career site LinkedIn. A mother of three who lived with her own mother in the Bronx, she felt a calling to help her community, friends said.

"She'd give you the shirt off her back," said Tom Ritter, 59, a plumber who lived downstairs from Familia and said she treated his now-22-year-old son like one of her own children.

"She was the sweetest person you ever want to meet," Ritter said.

Familia worked her entire police career in the Bronx precinct where she was killed while staffing the RV-like command post, stationed to help combat rising crime in the neighbourhood after a triple shooting in March.

Her policing earned praise even from a woman whose husband she had arrested.

"She gave me good advice, like a mother to a daughter," said Keisha Williams, 31, who said her husband was arrested on a marijuana charge last year. "She's good, but she's a tough cookie. She's a good cop. I'm just sad it was her."

Attorney General Jeff Sessions called the shooting "the latest in a troubling series of attacks on police officers over the past two years."

While tensions have been running high in recent years between police and black people around the country, there was no immediate indication the killing had a racial dimension. Bonds was black; Familia was black and Hispanic, her family having come from the Dominican Republic. She apparently had no previous contact with him.

Still, the attack recalled the 2014 ambush killings of two New York City officers who were gunned down in their cruiser by a man who had announced online moments before that he was planning to shoot two "pigs" in retaliation for the police chokehold death of Eric Garner in New York. The gunman then killed himself.

Bonds, also known as John Bonds, had a violent history and had vented his anger about police in a Facebook video last September. Rambling that law officers got away with killing and abusing people, he warned them to leave him alone or "we gonna do something."

"I'm not playing, Mr. Officer. I don't care about 100 police watching this," the 34-year-old said in a Facebook page otherwise filled largely with inspirational quotes and quizzes.

"It's time for people to wisen up," he added.

He had been released in 2013 after being sentenced to eight years in prison for a 2005 armed robbery in Syracuse. He had other arrests, including one in 2001, when as a teenager he was accused of attacking an officer with brass knuckles.

While he railed in his video about how inmates are treated behind bars, prison records show he had been written up more than two dozen times for disciplinary reasons - mostly for relatively minor infractions, but sometimes for top-level violations such as assaulting an inmate or fighting.

Early Wednesday, Bonds was caught on video leaving a convenience store, then moving tightly along the wall, pulling a hoodie over his head and walking purposefully toward the command post vehicle with gloved hands, according to police. The video didn't capture the shooting itself but showed him running away with a gun in his hand, police said.

Familia's partner frantically radioed for help, and officers caught up with Bonds about a block away and killed him in a hail of about 20 bullets when he pulled a stolen revolver, police said. He didn't get off a shot, authorities said.

All the NYPD's new patrol cars have bulletproof glass, and older vehicles are being fitted with window inserts to harden them against gunfire. But there are no plans to do the same with the rolling command centres, officials said.

-----

Associated Press writers Jennifer Peltz and Tom Hays in New York and Carolyn Thompson in Buffalo, New York, contributed to this report.