The shooting began at 23:20 local time on Wednesday about 40 miles (65km) north-west of Los Angeles, police say.
At least 200 people were reportedly inside the Borderline Bar and Grill, which was hosting a university student night, at the time of the attack.
Police have named the suspect as 28-year-old Ian David Long, who had suspected mental health issues.
Officials believe the US Marine Corps veteran and local resident took his own life inside the bar.
How did the shooting happen?
Police say the suspect, Ian David Long, was dressed in black, and forced his way into the bar after shooting the bouncer.
A college country music night was under way when the suspect apparently threw a smoke grenade before opening fire, witnesses say.
Police say he used a legally-owned .45 calibre Glock semi-automatic handgun, which had an extended magazine that is illegal in the state of California.
The extended magazine allowed the gun to carry more than its typical 11-bullet capacity.
Police say they do not yet know how many shots were fired, or whether the gunman ever reloaded during the attack.
One witness, Teylor Whittler, who was celebrating her 21st birthday said: “I was on the dance floor and I heard the gunshots, so I looked back and then all of a sudden everyone screamed: Get Down!
“It was a huge panic, everyone got up, I was trampled, I was kind of left on the floor until some guy came behind me and grabbed me and dragged me out.”
People escaped the bar by using chairs to break windows, while others reportedly sheltered inside the venue’s toilets.
What have police said?
Ventura County Sheriff Geoff Dean described the scene inside the bar as “horrific” and said there was “blood everywhere”.
He said first responders arrived less than three minutes after the first emergency calls from the venue were made.
Ventura Sheriff’s Sergeant Ron Helus, who later died in hospital, had tried to enter the active scene with a local highway patrolman when he was shot several times.
The husband and father-of-one had been a policeman for 29 years and was a professional firearms instructor.
He was due to retire next year.
“It saddens us all and tears at our emotions. He died a hero. He went in to save lives, to save other people,” the sheriff said.
Who is the suspect?
Police say they have had several minor contacts with Long in recent years, including in April 2018 when they were called to his house after a report of a disturbance.
During talks with police, he appeared “somewhat irate, acting a little irrationally” the sheriff said.
A police crisis intervention team interviewed him, and determined that it was not necessary to hold him against his will in a mental health facility under a so-called 5150 order.
The order allows authorities to involuntarily detain a person for up to 72 hours if it is believed that they pose a threat to themselves or others.
Mental health professionals believed that he suffered from PTSD (post-traumatic stress disorder), the sheriff said.
Police have just begun to search his home, and expect to know more about him and his possible motive soon.
Who are the other victims?
It is not yet clear who the other 11 victims inside the bar are, but the Wednesday night country music event is popular with local university students.
According to the bar’s website, Wednesday nights are college-themed and are open to students as young as 18.
The bar is located close to California Lutheran University, Pepperdine University and Moorpark College and is popular among students.
Some tearful reunions among those presumably (though unconfirmed) at Borderline or who knew them at Borderline. #Borderline #BorderlineShooting #ThousandOaksShooting @vcstar pic.twitter.com/0Ik19qFyGa
— Jeremy Childs (@Jeremy_Childs) November 8, 2018
Footage on local media of the aftermath shows injured young people being carried away from the scene by friends.
Police say at least 10 people are known to have been injured and others are self-reporting with injuries at local hospitals.
The latest in a long line
The US has suffered from mass shootings for decades, but most of the deadliest have occurred in recent years.
In the last two weeks alone, a man shot dead two people yoga studio in Florida, and another gunman opened fire on a synagogue in Pittsburgh, killing 11.
The deadliest attack in modern US history came last year in Las Vegas when a 62-year-old man opened fire on a crowd of 22,000 country music concertgoers from the 32nd floor of a nearby hotel, killing 58 and wounding hundreds.
One man who survived the attack on the Borderline Bar told CBS that several attendees on Wednesday night had also been present for the Las Vegas attack on the Route 91 Harvest Festival.
“It’s the second time in about a year and a month that this has happened,” Nicholas Champion said.
“It’s a big thing for us. We’re all a big family and unfortunately this family got hit twice.”
The previous most deadly attack was another just a year earlier, when 49 people were killed in Pulse – a gay nightclub – in June 2016. in Orlando.
Some students from Marjory Stoneman Douglas High School in Parkland, Florida – where 17 were killed in February – have taken up a public campaign for gun law reform in recent months but little in the way of change has emerged from legislators.
According to the website Gun Violence Archive, more than 12,000 people have been killed using firearms in the US so far this year, including about 3,000 people under 18.
That number does not include an annual estimate of 22,000 suicides via firearm.
What has reaction been?
President Trump tweeted on Thursday morning to say he been briefed on the shooting, describing it as “terrible”, and praising the bravery of the police officers involved.
I have been fully briefed on the terrible shooting in California. Law Enforcement and First Responders, together with the FBI, are on scene. 13 people, at this time, have been reported dead. Likewise, the shooter is dead, along with the first police officer to enter the bar….
— Donald J. Trump (@realDonaldTrump) November 8, 2018
….Great bravery shown by police. California Highway Patrol was on scene within 3 minutes, with first officer to enter shot numerous times. That Sheriff’s Sergeant died in the hospital. God bless all of the victims and families of the victims. Thank you to Law Enforcement.
— Donald J. Trump (@realDonaldTrump) November 8, 2018
Flags at the White House were lowered to half-mast to commemorate the victims.
Sheriff Dean, who on Thursday completes his last day serving as Ventura County sheriff, warned: “It doesn’t matter how safe your community is, it doesn’t matter how low your crime rate is – there are people who just don’t think properly everywhere, I don’t care where you are, and they commit horrific acts like this.”
A night that should've been filled with dancing & laughter turned tragic by senseless violence — our hearts are heavy for the people of Thousand Oaks and everyone affected by the mass shooting at the Borderline Bar, which took 12 lives including @VENTURASHERIFF Sergeant Ron Helus pic.twitter.com/7FmY3kw5mc
— LAPD HQ (@LAPDHQ) November 8, 2018
“There’s no way to process. There’s no way to make sense out of the senseless.”