VIRGINIA BEACH, Va. — A municipal building in Virginia Beach, Va., was turned into a scene of carnage on Friday afternoon after a longtime public utilities employee began firing indiscriminately at his co-workers with a handgun, the authorities said, killing a dozen people and injuring several others before dying after an extended shootout with the police.

It had been nearing closing time in an office offering some of the most mundane functions of city government, such as paying water bills and applying for building permits, when the employee, who was identified by the police on Saturday as DeWayne Craddock, began stalking through several floors firing at his colleagues, the authorities said.

The loud bursts of gunfire sent workers scrambling and barricading their office doors.

[Update: 12 Virginia Beach shooting victims identified.]

Zand Bakhtiari, 28, who works on the first floor of the city building where the shooting happened, looked out his window about 4 p.m. and saw people screaming and running. “I thought they were running to the scene of a bad car accident,” he said in a telephone interview late Friday.

At that point, he had not heard any gunfire. But right after that, his boss, who had just left, called in an order to shelter in place: There was an active shooter. Mr. Bakhtiari and others in his office shut the door and got down.

He then heard 50 to 60 gunshots. “It was a lot of shots,” he said. Five or 10 minutes later, a police SWAT team came and led them out.

[Virginia beach shooting suspect: Who is DeWayne Craddock?]

The identities of the victims were not immediately released nor was the motive of the attack. One of those injured was a police officer, who was saved by his bulletproof vest, said Chief James A. Cervera of the Virginia Beach Police Department, who said at an evening news conference that the scene could “best be described as a war zone.”