A disgruntled city employee armed with a .45-caliber handgun and several extended magazines opened fire at the Virginia Beach Municipal Center on Friday, killing at least 12 people before he was shot dead by police, authorities said.

Several other victims, including a cop, were hospitalized in the shooting spree, which began shortly after 4 p.m., police officials said.

“This is the most devastating day in the history of Virginia Beach,” Mayor Bobby Dwyer told reporters after the massacre. “The people involved are our friends, co-workers, neighbors and colleagues.”

The suspect, identified by the Wall Street Journal and CNN as 40-year-old DeWayne Craddock, walked into the building, which houses the city’s Planning, Public Utilities and Public Works departments, and “immediately began to indiscriminately fire upon all the victims,” Virginia Beach Police Chief Jim Cervera said at a news conference.

The building typically holds about 400 people, Cervera said, adding that victims were found on the first, second and third floors, in addition to one found outside, in a car.

Four officers who were working in the nearby police headquarters heard the gunfire, and rushed to the scene.

The cops took down the shooter after a “long-term” gun battle inside the building, during which the suspect emptied his gun and reloaded with another extended magazine. Craddock bought his weapon legally, CNN reported.

“They engaged with the suspect. The suspect did shoot a police officer. Officers then returned fire.

“The suspect is deceased,” Cervera said at the press ­conference. The injured cop was saved by his bulletproof vest, the chief added.

Police said the killer was a longtime employee of the Public Utilities Department, but Cervera said his name would not be publicly released until the families of deceased victims were ­notified.

The FBI, state police and local authorities are working jointly on the investigation, Cervera said.

Workers who were in the building described barricading themselves in their offices. Some hid under their desks.

Zand Bakhtiari, who was on the first floor when the shooting began, told the Virginian-Pilot newspaper that he heard numerous shots in quick succession.

“It was repeated, rapid gunfire,” he said.

City employee Megan Blanton told the Pilot that her supervisor pushed her and fellow workers into an office and propped a desk against a door.

“It felt like forever,” Blanton told the newspaper.

Workers in the building feared their co-workers were among the dead.

“I never thought this would happen in my building,” Arthur Felton, an 18-year Planning Department employee, told the ­Pilot.

“The people who were shot — I’m sure I know most of them.”

Virginia Gov. Ralph Northam said in a statement after the shooting that it was a “horrific day” for the state.

“This is unspeakable, senseless violence,” he said.

“My thoughts continue to be with the victims and their families.”

With Wires