The suspect, described by officials as a disgruntled city employee in Virginia Beach, fired indiscriminately in a municipal building.
The gunman was killed in an exchange of gunfire with police. His identity has not been released.
Officials said an officer was wounded when a bullet struck his vest.
How did the shooting unfold?
The attack began shortly after 16:00 (20:00 GMT), at Virginia Beach Municipal Center, in an area which is home to a number of city government buildings. The area was put into lockdown by police and employees were evacuated.
“We just heard people yelling and screaming at people to get down,” Megan Banton, an administrative assistant in the building, told local television news station WAVY.
One of the victims was shot outside in a car, and the rest were found over three floors of the government building.
Four officers entered the building and located the gunman inside and “immediately engaged” him, police chief James Cervera said. The attacker was then shot dead.
The police chief described the scene as a “war zone”.
“I want you to know that during this gun battle, basically the officers stopped this individual from committing more carnage in that building,” Mr Cervera said.
Police recovered a rifle and a handgun, thought to have been used by the suspect, at the scene.
As police cars, blue lights flashing, line the perimeter of the Virginia Beach municipal offices, rain continues to fall.
At the end of a shortened working week following Monday’s Memorial Day holiday, many families are facing a future without their loved ones.
Survivors speak of sleepless nights ahead. Virginia’s largest city has now become the site for this country’s largest mass shooting in 2019.
The latest tragedy has taken place ahead of the annual National Gun Violence Awareness Day on Sunday. This will provide little comfort to those who want to see an end to the easy access to guns which frequently bring schools and cities across America to prominence for all the wrong reasons.
What is known about the victims?
The identities of the 12 victims and the suspect have not yet been released. Mr Cervera said the suspect’s name would only be released after the victims’ families had been notified.
“We’re going to mention his name once and then he will forever be referred to as ‘the suspect’, because our focus now is the dignity and respect to the victims in this case and to their families,” he said.
At least four people are known to have been wounded, including a police officer, but the severity of their injuries remained unclear.
The injured officer’s life was saved by his bulletproof vest.
A White House spokesman said President Trump had been briefed about the shooting.
The FBI was at the scene helping local authorities investigate the shooting, US media reported.
‘The most devastating day’
Virginia Senator Tim Kaine said on Twitter he was “devastated to learn of the tragic shooting tonight in Virginia Beach”.
“My heart is with everyone who lost a loved one, and I’m praying for a swift recovery for all those who have been injured,” he said.
Robert Dyer, the city’s mayor, said: “This is the most devastating day in the history of Virginia Beach.”
Virginia governor Ralph Northam described the incident as a “tragic day” for the city and the state.
“Our hearts ache over the senseless violence that has been inflicted upon the Virginia Beach community today,” he told reporters.
According to US tracking website Gun Violence Archive, the incident is the 150th mass shooting in the US so far in 2019.
The site defines a mass shooting as a gun attack in which at least four people are either killed or wounded.