A New York City police officer was shot and killed in an “unprovoked attack” as she was sitting in a marked police vehicle early Wednesday in the Bronx, authorities said.

Officer Miosotis Familia was inside the large vehicle — known as a mobile command post — with her partner at 12:30 a.m. when a gunman fired through a window and struck Familia in the head, police said. The city’s police commissioner called the shooting an assassination.

Familia, a 12-year NYPD veteran, was taken to a hospital in extremely critical condition, police said. Police Commissioner James P. O’Neill announced on Twitter several hours later that Familia had died. Familia’s partner was not wounded in the attack.

In a statement Wednesday afternoon, Attorney General Jeff Sessions said Familia was “unjustly targeted and murdered in a cowardly, unprovoked attack.”

“She will be remembered for her years of service and for the example of selflessness that she set protecting people on our streets,” Sessions said. “This murder in cold blood is a tragedy, and sadly it is the latest in a troubling series of attacks on police officers over the past two years.”

Police said Familia was wrapping up her shift when the gunman fired. “My partner’s shot! My partner’s shot! My partner’s shot! Hurry up central!” her partner was heard screaming into a police radio, according to the Associated Press.

Two other officers confronted the suspected gunman about a block away from the scene of the shooting, police said. The shooting suspect was shot and killed after he drew a revolver, police said. He was identified by authorities as 34-year-old Alexander Bonds.

Alexander Bonds (New York Department of Corrections and Community Supervision)

A bystander was shot during that encounter. Police said that person is in stable condition.

It remains unclear what prompted the attack, officials said. A police spokesman said Familia did not know Bonds.

Bonds, who also went by the name John Bonds, was paroled in May 2013 after serving seven years for robbery in Onondaga County, according to the New York Department of Corrections and Community Supervision. He also served more than six months in prison in 2004 for selling a controlled substance.

The shooting was reminiscent of the 2014 killings of two New York police officers who were shot at point-blank range while sitting in a police car in Brooklyn.

“It’s clear that this was an assassination,” New York City Mayor Bill de Blasio said at the time. “These officers were shot execution-style, a particularly despicable act which goes to the heart of our society and our democracy.”

Authorities said the gunman in the 2014 ambush had declared his intention on Instagram to kill officers as retribution for the deaths of Michael Brown and Eric Garner, black men who were killed by police that year.

The Dec. 20, 2014, killings of NYPD Officers Wenjian Liu and Rafael Ramos inflamed tensions between the city’s police force and de Blasio, who during his 2013 mayoral campaign had strongly criticized the department’s “stop-and-frisk” tactic. After the ambush, police union officials accused the Democratic mayor of feeding anti-police sentiment. The rift prompted hundreds of police officers to turn their backs as de Blasio spoke at the funeral of one of the two slain officers.

In 2016, law enforcement fatalities spiked to their highest level in five years, with 135 officers killed in the line of duty, according to the National Law Enforcement Officers Memorial Fund, a nonprofit group that monitors line-of-duty deaths. The rising death toll rattled police officers nationwide.

Ambushes dominated the news after a pair of July 2016 attacks in which eight officers were shot in what authorities described as targeted attacks fueled by anger over how police use force on minorities.

An ambush in Dallas on July 7, 2016 — the deadliest single day for law enforcement since the Sept. 11, 2001, terrorist attacks — targeted officers patrolling a protest over deadly police shootings in Baton Rouge and Falcon Heights, Minn., over the preceding days. Five officers were killed and nine others wounded before police killed the attacker.

Ten days later, another attacker sought out law enforcement officers in Baton Rouge, killing two police officers and a sheriff’s deputy before he was felled by a sniper. Officials said in a report released last week that the gunman had researched the officers involved in the deadly shooting of Alton Sterling, a black man killed outside a Baton Rouge store in an incident partially captured on video.

In November, two Iowa police officers sitting in their squad cars were killed in a pair of ambush attacks. A San Antonio officer writing a ticket was ambushed and killed not long after.

These episodes helped fuel an uptick in police officer deaths last year, with 64 officers fatally shot, a 41 percent increase from the previous year, according to the Memorial Fund. Nearly one in three officers fatally shot was killed in what were deemed to be ambush attacks like those in Dallas and Baton Rouge.

#NYPD PO Miosotis Familia has been assassinated in an unprovoked attack on cops assigned to keep NYers safe. Keep her family in your prayers pic.twitter.com/yhRB7H5bvi

Overall, law enforcement line-of-duty deaths have declined since the 1970s, when twice as many police officers were fatally shot each year and twice as many officers were killed annually. Still, in recent years, police have said they feel demonized by protests against how law enforcement officers use deadly force. Demonstrations have erupted in cities such as New York, Baltimore, Cleveland, Cincinnati, Chicago and San Francisco after high-profile killings by officers.

Before 2016, traffic-related incidents — rather than shootings — were the leading cause of police deaths for most of the past two decades. Last year, nearly half of all police officer deaths were gun-related, the largest share in any year since 1994.

So far this year, at least 65 officers have been killed — a 25 percent increase over the same period last year, according to the Memorial Fund. Nearly half of them were killed by gunfire, but the overall increase in fatalities was largely fueled by what the fund called “other causes,” which can include boating accidents and illnesses.

I offer my deepest condolences to Officer Familia’s loved ones and fellow members of the NYPD. Today, we all mourn one of New York’s Finest.

Familia, 48, joined the New York Police Department in July 2005. She was a mother of three, said Patrick J. Lynch, president of the Patrolmen’s Benevolent Association.

In a statement, Lynch said of Familia:

[She] gave her life protecting a neighborhood that had been plagued by gang gun violence. Fully knowing the dangers that she faced, she suited up in uniform every day and stood tall against those who threaten and terrorize the good folks of the Bronx. As we mourn her death and support her family, friends and colleagues, we ask for your help. Violence against police officers cannot stand. When you see or hear someone making threats against NYC police officers you need to let us know, you need to be our eyes and ears.

Vivian Gomez, who lived in the same Bronx apartment building as Familia, said Wednesday morning that she’d heard about a police officer who was shot, but she did not know until a Washington Post reporter contacted her that the slain officer was her upstairs neighbor.

She didn’t know Familia well, Gomez said, but they often saw each other in passing.

“When our paths crossed, she was either coming to or from work; I know she loved the job,” Gomez told The Post. “I never heard her say a negative thing about her job. Oftentimes, people would gripe about the hours, the long days. I never heard her say, ‘I dislike my job’ or ‘It’s tough.’ She always had a smile on her face.”

Gomez said Familia appeared to be devoted to her children.

“She always seemed to be a very caring mother. … Every time I saw her, she had her kids,” Gomez said. “They all seemed to be a very close-knit family. I found her always to be a very warm spirit.”

A relative reached by The Post on Wednesday declined to comment.

“It’s just an unfortunate situation in the time we live in, where cops are targeted,” Gomez said of Familia’s death. “I know there’s a lot of distress about lack of justice in our community. … She’s a real face behind the badge.”

Peter Holley and Julie Tate contributed to this report, which has been updated.