A New Jersey police officer and three civilians have died after a gun battle prompted by what is believed to have been a drug deal gone bad in Jersey City, officials said.

The slain officer was shot at the Bay View Cemetery allegedly by two suspects who fled to a Kosher supermarket at Wilkinson Avenue and Martin Luther King Dr. in Jersey City, police said.

The dead included two suspects, Jersey City Police Chief Michael Kelly said.

“Our officers were under fire for hours,” the chief said.

He would not say exactly what set off the shooting but that he believes the officer who was killed was trying to stop some “bad guys.”

City Public Safety Director James Shea said that authorities believe the bloodshed was not an act of terrorism but that it was still under investigation.

Two other officers were wounded but were later released from the hospital, authorities said.

The bullets started flying early in the afternoon in the city of about 270,000 people, situated across the Hudson River from the Statue of Liberty.

The shooting spread fear through the neighborhood, and the nearby Sacred Heart School was put on lockdown as a precaution.

SWAT teams, state police and federal agents converged on the scene, and police blocked off the area, which in addition to the school and supermarket included a hair salon and other shops. Dozens of bystanders pressed against the police barrier to capture the action on their cellphones, some whooping when bursts of fire could be heard.

Video shot by residents recorded loud volleys of gunfire reverberating along one of the city’s main streets and showed a long line of law enforcement officers pointing guns as they advanced, yelling to bystanders, “Clear the street! Get out of the way!”

“ It’s like firecrackers going off,” said Andy Patel, who works at a liquor store about three blocks away. “They were shooting like crazy. … The cops were clearing everyone off the streets.”

Gov. Phil Murphy and President Donald Trump were both briefed on the incident. Murphy visited the scene after the shootout. Trump called the shooting “horrific” and said his thoughts and prayers were with the victims and their families.