The suspect entered the Borderline Bar and Grill in Thousand Oaks, 40 miles northwest of Los Angeles, at 11.20pm local time and started firing into a crowd of around 200 people.
A sheriff's sergeant responding to reports of the shooting died after being "struck multiple times with gunfire", Ventura County sheriff Geoff Dean said.
The 29-year-old suspect, described as dressed all in black with a mask covering his face, died inside the bar. His death took the total number of fatalities to 13.
"It is a horrific scene in there, there is blood everywhere, and the suspect is part of that," Mr Dean said.
The sheriff added that around 10 other people were shot and injured and an additional 10-12 were walking wounded. No other information on the victims was immediately known.
"We don't know who shot anybody at this point," Mr Dean said, adding that the suspect was yet to be identified.
Authorities do not yet know how the gunman, who was armed with a .45-caliber handgun, died, or what his motive might have been.
Witnesses said the suspect shot a security guard standing at the door of the bar before entering the building and throwing "smoke grenades all over the place". He then fired into the crowd, apparently at random. A female cashier was said to be among the victims.
At least 30 shots were fired before people inside the bar began using chairs to smash windows to escape, the witness said. Police were at the scene three minutes after the first 911 call was made.
Donald Trump said he had been "fully briefed on the terrible shooting" and praised law enforcement, saying "great bravery" had been shown by the police.
Sergeant Ron Helus, the police officer killed outside the bar, had a wife and son and was due to retire within the next 12 months after 29 years service.
"Ron was a hardworking, dedicated sheriff's sergeant who was totally committed," Mr Dean said, "and tonight, as I told his wife, he died a hero because he went in to save lives."
Teylor Whittler, 19, was on the dance floor when the shooting started. She said: "I heard the gunshot, turned around and saw him shoot a couple more times.
"Within a split second everyone yelled ‘get down’. I ran to where the back door is, and everyone dog-piled on top of each other. It was silent for a couple of seconds and then all of a sudden a couple of guys started running to the back door and said ‘get up he’s coming’.
"It was a huge panic, everyone tried getting up, and some guy came behind me, lifted me up and said ‘let’s go’. I got a bar stool thrown at my head because they were trying to use it to get out.”
Nick Steinwender, student body president at nearby California Lutheran University, rushed to the scene when he heard about a shooting at the bar where he knew friends and fellow students were inside.
"It was chaos, people jumping out of windows, people hopping over gates to get out," he told KABC-TV.
The website for Borderline bar showed that Wednesday nights are College Country Nights that last from 9 pm until 2am.
Nearby Pepperdine University said "multiple ... students were on site" at the bar and staff were "working to identify and provide support to those students".
Matt Wennerstrom, 20, took over carrying someone who had been shot. He has blood on his t shirt. He tried to get as many people as he could out of the bar. #ThousandOaksShooting pic.twitter.com/LVZkftr8db
— Brittny Mejia (@brittny_mejia) November 8, 2018
Thousand Oaks, a wealthy area close to several colleges and universities, is ranked as one of America's safest cities by the FBI.
The US has suffered a succession of deadly incidents involving guns in recent days, including a shooting in a yoga studio in Florida that left two people dead and five injured.
Last month a gunman entered the Tree of Life synagogue in Pittsburgh just as Shabbat services were beginning and started shooting, killing 11 people and wounding six others in the deadliest attack on Jews in US history.