Terrified patrons -- many of whom were college students -- scrambled for the exits after the gunman started shooting people with a handgun in the Borderline Bar and Grill at around 11:20 pm on Wednesday.
"They ran out of the back doors, they broke windows, they went through windows. They hid up in the attic, they hid in the bathroom," Ventura County Sheriff Geoff Dean said.
The assailant, identified as Ian David Long, a troubled former machine gunner who served a tour in Afghanistan, died of a self-inflicted gunshot wound.
Dean told reporters that Long shot an unarmed security guard who was standing outside the bar before entering and opening fire at random inside.
Twenty-three people were injured -- some from "jumping out of windows, diving under tables," Dean said -- and treated at area hospitals.
A year ago, 58 people were shot dead at a country music festival in Las Vegas, the worst mass shooting in modern US history, and several of the patrons in the California bar had also been at the Nevada concert.
"I can't believe I'm saying this again," Molly Maurer posted on Facebook. "I'm alive and I'm home safe.
According to the Pentagon, Long served in the Marine Corps from August 2008 to March 2013.
He attained the rank of corporal and saw combat while deployed in Afghanistan from November 2010 to June 2011.
"He had perfect form," bar patron Teylor Whittler told Fox News. "He looked like he knew what he was doing."
- 'Like hell' -
Police on Thursday were searching Long's house in Newbury Park, near Thousand Oaks, where he reportedly lived with his mother.
Long was found dead by police in an office at the bar and is believed to have shot himself, Dean said.
Authorities so far had no indication of a motive, or of any connection to terrorism.
"We have no idea what the motive was at this time," Dean said.
"Obviously he had something going on in his head that caused him to do something like this," he said. "He had some kind of issues."
Dean described the scene inside the bar as "like hell."
He said his department had "several contacts" with Long over the years, for minor incidents including a traffic collision, and in 2015 when he was beaten up at a local bar.
In April this year, deputies were called to his house for a disturbance and found him "acting a little irrationally."
"They felt he might be suffering from PTSD, the fact he was a veteran and had been in the corps," Dean said.
"They called out our crisis intervention team, our mental health specialists who met with him, talked to him, and cleared him."
Dean said Long was armed with a single handgun, a .45 caliber Glock 21, which he purchased legally.
- 'Ultimate sacrifice' -
Among those killed was a three-decade veteran of the sheriff's department, 54-year-old Sergeant Ron Helus, who was married, had a grown son and was close to retirement.
"He went in there to save people and made the ultimate sacrifice," Dean said.
He said Helus was on the phone with his wife when he got the report of the shooting and he told her, "'Hey, I have to go. I love you. I'll talk to you later.'"
Helus and a highway patrol officer exchanged gunfire with Long, he said, and the sergeant was shot "several times."
Matt Wennerstron, a 20-year-old college student, said the shooter apparently had a 10-15 round magazine on his gun.
"When (he) started to reload, that's when we got people out of there and I didn't look back," Wennerstron said.
He said he and others smashed their way out of the bar onto a balcony and then jumped down to safety.
Jasmin Alexander, who was with around 15 friends at the bar, said there was chaos and confusion inside when shots rang out.
"We were just at the bar, having fun, dancing," she told reporters.
"All of a sudden we heard the 'bang, bang' of the gunshots and it just started going crazy and people were pushing.
"We didn't take it seriously at first... because it sounded like firecrackers and everyone just dropped down to the floor."
President Donald Trump ordered the US flag at the White House and other government buildings to be flown at half-staff following the shooting, which came just 10 days after a gunman killed 11 worshippers at a synagogue in Pittsburgh.