JERSEY CITY, N.J.—Two gunmen went on an hourslong shooting rampage Tuesday, targeting a Jewish grocery store and getting into a firefight with police that killed four people, including a police officer, as well as the two suspects, officials said.

The shootings began at the Bay View Cemetery in Jersey City when Jersey City Police Detective Joseph “Joe” Seals confronted the suspects and was shot and killed by them, officials said. The suspects, two men believed to be dressed in black and armed with higher-powered rifles, then...