An ex-convict’s hate for cops drove him to assassinate an NYPD officer in the Bronx with a stolen handgun early Wednesday as she sat in a police command vehicle on anti-gang detail, officials said.

Miosotis Familia, 48, a 12-year veteran and a mother of three, was targeted in “an unprovoked attack on police officers who were assigned to keep the people of this great city safe,” said Police Commissioner James O’Neill at an early morning news conference with Mayor Bill de Blasio at St. Barnabas Hospital in the Bronx.

The fallen officer’s partner in the vehicle frantically put out a radio call for help before other anti-crime cops in the area responded. They confronted the gunman, Alexander Bonds, 34, of the Bronx, as he ran on Morris Avenue, police said, and officers shot and killed him after he drew his handgun.

“She was on duty serving this city, protecting people, doing what she believed in, and doing the job she loved,” de Blasio said of Familia, who lived in the Kingsbridge section of the Bronx and worked out of the 46th precinct.

A male bystander was shot in the abdomen during the officers’ confrontation with Bonds and was in stable condition at Lincoln Hospital, an NYPD spokesman said.

Familia, wearing her department uniform, was sitting in the passenger seat of the police van parked in Fordham Heights at about 12:30 a.m. Wednesday, officials said. Bonds walked up to the vehicle with a 38-caliber handgun and fired one shot through the side window, striking her in the face.

advertisement | advertise on newsday

Familia was transported to St. Barnabas Hospital where she died, police said. The Ruger handgun police believe Bonds used to kill Familia was recovered. Investigators said the weapon was stolen in West Virginia in 2013.

Shortly before 12:30 p.m. Wednesday, the Rev. Terry Lee, of Brooklyn, and several other pastors, held an impromptu prayer service inside the precinct for Familia and her distraught colleagues.

Speaking to reporters outside, Lee described a somber scene inside the two-story brick station house at the corner of Ryer Avenue and E. 181st Street.

“You can feel the pain . . . it’s a painful moment,” Lee said.

Familia had been assigned to the Fordham Heights location near 183rd Street and Morris Avenue in the 46th Precinct because of a recent uptick in gang shootings, police said. While crime is down 6.7 percent in the precinct this year, shootings are up 12.5 percent, according to NYPD data.

“Regularly achieving lower and lower crime figures means absolutely nothing when one of our own is brutally shot and killed,” O’Neill wrote in an internal email message to all NYPD members obtained by Newsday.

The officer’s killing reverberated beyond the city.

In a statement, U.S. Attorney General Jeff Sessions called Familia’s death a “murder in cold blood” and another in a “troubling series of attacks on police officers over the past two years.”

Outside the 46th Precinct, stunned officers exchanged hugs and consoled one another. Flowers lined the steps of the precinct, just blocks from where Familia was gunned down. A blue and black striped banner draped across the precinct’s front entrance.

The manner in which Familia was shot — seemingly ambushed as she sat in an NYPD vehicle with her partner by a gunman fueled by a hate for cops — hearkened back to the December, 2014 execution-style killings of officers Wenjian Liu, 32, and Rafael Ramos, 40, in the Bedford-Stuyvesant section of Brooklyn. The gunman in that shooting fled and killed himself a short time later.

advertisement | advertise on newsday

“Make no mistake,” O’Neill wrote in the internal email, “Officer Familia was murdered for her uniform and for the responsibility she embraced.”

Investigators said Bonds, also known as John Bonds, was seen on surveillance video in the moments just before the shooting exiting a bodega, pulling up his hoodie and then approaching the police van. The actual shooting was too indistinct to see in the video, police said.

Wearing black gloves and a hoodie on a warm summer night, Bonds seemed “dressed to kill,” said one high-ranking police official later Wednesday.

Bonds was arrested in Syracuse on July 2, 2005 after he and a juvenile accomplice robbed a victim at gunpoint, Onondaga County District Attorney William J. Fitzpatrick said in a statement. Bonds was sentenced to eight years in prison after pleading guilty to robbery in the first degree, Fitzpatrick said.

State corrections officials said he was sent to the Attica Correctional Facility after his 2006 conviction. He was released on parole for five years in May 2013.

advertisement | advertise on newsday

Since his release Bonds only had minor quality of life contacts with the NYPD, officials said.

Bond’s social media postings included rants against cops and the fact that his time in prison didn’t do him any good, the official said. A video blog posted by Bonds complained that police officers in California pulled a teenager off a bike and harassed the 16-year-old, the official said.

“There is no reason it was anything more than ‘I just hate cops,’ ” the official added about Bond’s motive. Bonds’ girlfriend told detectives he seemed schizophrenic and paranoid of the police.

Lee said he did not know Familia but felt compelled to come to the police station to offer prayers upon hearing she was a mother.

The Rev. Kelly Scott of the Way to Life Ministries in Harlem said she was there to pray “for the strength” of Familia’s family.

“Officer Familia is a hero,” Scott said.

Familia was the 866th NYPD officer to die in the line of duty and the third female officer killed in the line of duty in modern times.

The most recent NYPD officer to die from gunshots was Det. Steven McDonald, 59, of Malverne, who died in January from the effects of wounds from a shooting in Central Park 31 years earlier. Sgt. Paul Tuozzolo, 41, of Huntington was shot and killed in the Bronx on Nov. 4, 2016.

CORRECTION: An earlier version of this story misstated the address of the suspect, Alexander Bonds, because of incorrect information from police.