THOUSAND OAKS, Calif. — Terrified patrons hurled barstools through windows to escape or threw their bodies protectively on top of friends as a Marine combat veteran killed 12 people at a country music bar in an attack that added Thousand Oaks to the tragic roster of American cities traumatized by mass shootings.

Dressed all in black with his hood pulled up, the gunman apparently took his own life as police massed at the Borderline Bar & Grill in Southern California.

The motive for the attack late Wednesday night was under investigation.

The killer , Ian David Long, 28, was a former machine gunner and Afghanistan war veteran who was interviewed by police at his home last spring after an episode of agitated behavior that authorities were told might be post-traumatic stress disorder.

Opening fire with a handgun with an illegal, extra-large magazine, Long shot a security guard outside and then went in and took aim at employees and patrons, authorities said. He also used a smoke bomb, according to a law enforcement official who was not authorized to discuss the investigation publicly and spoke on condition of anonymity.

Survivors of the rampage — mostly young people who had gone out for college night at the Borderline, a hangout popular with students from nearby California Lutheran University — seemed to know what to do, having come of age in an era of active-shooter drills and deadly rampages happening with terrifying frequency.

Several of the survivors said they were also at the outdoor country music festival in Las Vegas last year when a gunman in a high-rise hotel killed 58 people.

Many of the hundreds of patrons dived under tables, ran for the exits, broke through windows or hid in the attic and bathrooms, authorities and witnesses said.

"Unfortunately our young people, people at nightclubs, have learned that this may happen, and they think about that," Ventura County Sheriff Geoff Dean said. "Fortunately it helped save a lot of lives that they fled the scene so rapidly."

Matt Wennerstrom said he pulled people behind a pool table, and he and friends shielded women with their bodies after hearing the shots. When the gunman paused to reload, Wennerstrom said, he used a barstool to shatter a window and then helped about 30 people escape. He heard another volley of shots after they got out.

"All I wanted to do was get as many people out of there as possible," he told KABC-TV. "I know where I'm going if I die, so I was not worried."

The dead included a veteran sheriff's deputy who rushed in to confront the gunman, as well as 22-year-old man who planned to join the Army, a freshman at nearby Pepperdine University and a recent Cal Lutheran graduate.

"It's a horrific scene in there," Dean said in the parking lot. "There's blood everywhere."

The tragedy left a community that is annually listed as one of the safest cities in America reeling. Scores of people showed up to donate blood for the wounded.

All morning, people looking for missing friends and relatives arrived at a community center where authorities and counselors were informing the next-of-kin of those who died. Many walked past TV cameras with blank stares or tears in their eyes. In the parking lot, people comforted each other with hugs or a pat on the back.

Jason Coffman received the news that his son Cody, 22, who was about to join the Army, was dead. Coffman broke down as he told reporters how his last words to his son as he went out that night were not to drink and drive and that he loved him.

"Oh, Cody, I love you, son," Coffman sobbed.

It was the nation's deadliest such attack since 17 students and teachers were killed at a Parkland, Florida, high school nine months ago. It also came less than two weeks after a gunman massacred 11 people at a synagogue in Pittsburgh.

Democratic Gov.-elect Gavin Newsom, in his first public appearance since winning office on Tuesday, lamented the violence that has come again to California.

"It's a gun culture," he said. "You can't go to a bar or nightclub? You can't go to church or synagogue? It's insane is the only way to describe it. The normalization, that's the only way I can describe it. It's become normalized."

President Donald Trump praised police for their "great bravery" in the attack and ordered flags flown at half-staff in honor of the victims.

Authorities converged on Long's home in Newbury Park, about 5 miles from the Borderline bar, in a search for clues to what set him off.

"There's no indication that he targeted the employees. We haven't found any correlation," the sheriff said. "Maybe there was a motive for this particular night, but we have no information leading to that at all."

Long was in the Marines from 2008 to 2013, rose to the rank of corporal and served in Afghanistan in 2010-11 before he was honorably discharged, the military said. Court records show he married in 2009 and was divorced in 2013.

Authorities said he had no criminal record, but in April officers were called to his home, where deputies found him angry and acting irrationally. The sheriff said officers were told he might have PTSD because of his military service. A mental health specialist met with him and didn't feel he needed to be hospitalized.

Tom Hanson, 70, who lives next door to Long and his mother, said Thursday that he called the police about six months ago when he heard "heavy-duty banging" and shouting coming from the Longs' home.

"I was concerned because I knew he had been in the military," he said.

Hanson said the sheriff's deputy who arrived took his information, but he never learned more about what happened and hadn't spoken to Long since then.

Long was armed with a Glock 21, a .45-caliber pistol designed to hold 10 rounds plus one in the chamber, according to the sheriff. But it had an extended magazine — one capable of holding more ammunition — that is illegal in California, Dean said.

Sheriff's Sgt. Ron Helus and a passing highway patrolman arrived at the club around 11:20 p.m. in response to several 911 calls, heard gunfire and went inside, the sheriff said. Helus was immediately shot, Dean said.

The highway patrolman pulled Helus out, then waited as a SWAT team and scores more officers arrived. Helus died at a hospital.

By the time officers entered the bar again, the gunfire had stopped, according to the sheriff. They found 12 people dead inside, including the gunman, who was discovered in an office, the sheriff said.

"There's no doubt that they saved lives by going in there and engaging with the suspect," said Dean, who was set to retire on Friday. He praised the slain officer — a close friend — as a hero: "He went in there to save people and paid the ultimate price."

One other person was wounded by gunfire, and as many as 15 others suffered minor injuries from jumping out windows or diving under tables, authorities said.

Shootings of any kind are extremely rare in Thousand Oaks, a city of about 130,000 people about 40 miles (64 kilometers) from Los Angeles, just across the county line.

The Borderline, which has a large dance hall along with several smaller areas for eating and drinking, was holding one of its regular "College Country Nights."

Nick Steinwender, Cal Lutheran student body president, told KTLA-TV he immediately started receiving messages about the shooting, and he and his roommate went to the scene to offer rides back to campus or moral support.

"It's going to be a very somber day," Steinwender said. "I know we don't have all the details in yet, but you know, it just feels like it's an attack on our community. You know, I think it's going to be something that we're going to have to come together and move past."

The bar is also close to several other universities, including California State University Channel Islands in Camarillo, Pepperdine in Malibu and Moorpark College in Moorpark.

Around midday, the body of the slain sheriff's officer was taken by motorcade from the hospital to the coroner's office. Thousands of people stood along the route or pulled over in their vehicles to watch the hearse pass. Firefighters use two ladder trucks to raise a giant American flag over the route.

Helus was a 29-year veteran of the force with a wife and son and planned to retire in the coming year, said the sheriff, choking back tears.

___

AP journalists Andrew Dalton, Amanda Lee Myers, John Antczak and Brian Melley in Los Angeles, Michelle A. Monroe in Phoenix and Michael Balsamo in Washington contributed to this report.