THOUSAND OAKS, Calif. — A gunman firing seemingly at random killed a dozen people inside a crowded country-music bar here late Wednesday, authorities said, a toll that included a sheriff’s deputy who had raced inside to confront the attacker.

Authorities said the gunman — identified as Ian David Long, a 28-year-old Marine veteran who was cleared by a mental-health specialist after an encounter with police earlier this year — was found dead inside after apparently killing himself. Ventura County Sheriff Geoff Dean said Thursday morning that investigators have not been able to determine a motive.

The bloodshed spread throughout the Borderline Bar & Grill, a popular nightspot in Thousand Oaks, Calif., a city near Los Angeles. When the gunfire began, people were line dancing during the venue’s “College Country Night,” witnesses said. That detail evoked the massacre of 58 people at a country-music festival in Las Vegas a little more than a year earlier — a connection deepened when some of those who escaped Borderline said they had also survived that massacre.

Police said Long, wearing a black sweater and wielding a .45-caliber Glock handgun with an extended magazine, approached the bar and shot a security guard standing outside. He then headed in and shot other employees before turning his fire on patrons, Dean said.

“It’s a horrific scene in there,” Dean, who is set to retire Friday night, told reporters. “There’s blood everywhere.”

The gunfire set off a panic, as patrons grimly familiar with stories of shooting rampages at churches, schools, movie theaters, offices and other locations across the country scrambled for safety and shelter.

“They ran out of back doors, they broke windows, they went through windows, they hid up in the attic, they hid in the bathroom," Dean said. "Unfortunately, our young people, people at nightclubs, have learned that this may happen. They think about that. Fortunately, it probably saved a lot of lives that they fled the scene so rapidly.”

Benjamin Ginsburg, 23, said he hid under a table and then, hearing gunfire from the front, ran with other people toward the rear exits. Teylor Whittler, 19, said a man named Ethan “picked me up because I kept getting ... trampled,” carrying her out the back door and saving her life. She said many people then hid behind bushes, in their cars or underneath the vehicles in the parking lot.

Among the dead was Ron Helus, a veteran sergeant in the Ventura County Sheriff’s Office who was mortally wounded when he responded to the incident just minutes after 911 calls began flooding in, authorities said.

Helus and a Highway Patrol officer headed into the club and exchanged fire with the attacker, Dean said. Helus, a 29-year veteran of the force with a grown son, had been on the phone with his wife when he got the call about the shooting and headed to the club, Dean said. During the shootout, he was struck several times.

“He died a hero,” Dean said, his voice cracking, “because he went in to save lives."

The latest attack carried echoes and reminders of others. The descriptions of chaos inside the club were similar to those reported during the slaughter of 49 clubgoers at Pulse nightclub in Orlando in 2016; the rampage in California occurred about 100 miles away from a community center where 14 were killed during a 2015 terror attack in San Bernardino, Calif.

Dean alluded to these earlier attacks, saying the carnage in Borderline “is part of the horrors that are happening in our country and everywhere, and I think it’s impossible to put any logic or any sense to the senseless.”

When asked by a reporter what it looked like inside the venue, Dean responded: “Like hell.”

California Gov. Jerry Brown (D) said in a statement that “our hearts ache today for the victims of this heinous act” and thanked Helus and other law enforcement officials “who took heroic action to save lives.” President Trump ordered flags to be flown at half-staff until sunset on Saturday in response to the “terrible act of violence perpetrated in Thousand Oaks.”

In addition to those slain at the club, Dean said he believed between eight and 15 other people were injured, mostly with cuts from diving under tables and jumping through windows. One person had a minor gunshot injury, he said.

Cody Coffman, a 22-year-old who had been talking to recruiters about fulfilling his dream of joining the Army, was among those killed, his father said Thursday morning.

“I am speechless and heartbroken,” Jason Coffman said outside the Thousand Oaks Teen Center, where families were gathering in the wake of the attack.

Coffman, at times so overwhelmed he could not speak, leaned on his father-in-law to steady himself. He said he last saw his son as the younger man was heading out last night.

“The last thing I said was, ‘Son, I love you,'” he said.

Sarah Deson, 19, said Cody Coffman stood in front of her as the shooter approached from the front entrance. Coffman yelled for everyone to get down and told her to run for the front door as the shooter moved farther into the bar, she said.

“Cody saved so many people last night, he was shielding people and getting them out,” she said.

A group of more than a dozen people walked out of one building at the center huddled together. The teen center had become a de facto staging ground for relatives because authorities were notifying families and close friends there about victims. Families could be seen crying and hugging each other; outside, a man with a hoodie pulled up over his head sat on the curb while another man sat nearby and placed a hand on his shoulder.

What could have motivated the attack remained a mystery to authorities, Dean said. The FBI said it was processing the crime scene at the bar as well as the attacker’s home and vehicle at the request of Dean’s office and would pursue leads “to identify any possible motivation.”

The Marine Corps said Long served between August 2008 and March 2013. He served as a machine gunner in Afghanistan from November 2010 to June 2011 and became a corporal two months later. California State University Northridge said Long was a former student there who last attended the school in 2016.

Gen. Robert B. Neller, commandant of the Marine Corps, tweeted on Thursday his condolences and pointedly referred to Long as “that ex-Marine” in his message:

Heartfelt condolences to those suffering from the tragic & senseless act of violence #ThousandOaks. That ex-Marine's despicable actions run counter to what the vast majority of veterans are rightfully known for: serving w/ honor then making positive contributions to society

Dean said Long lived in Newbury Park, Calif., a town near Thousand Oaks. Police have had “several contacts” with Long over the years, Dean said, most of them for minor events including traffic accidents. In April, deputies were called to Long’s home for a disturbance call, Dean said.

“They went to the house, they talked to him," he said. “He was somewhat irate, acting a little irrationally. They called out our crisis intervention team, our mental health specialist, who met with him, talked to him and cleared him.”

Part of the discussion among those responding to Long’s home was that “he might be suffering from PTSD,” Dean said, pointing to the 28-year-old’s military service. But “the mental health experts out there cleared him that day,” Dean continued, and no involuntary holds were placed on Long.

The gun used in the bar massacre appeared to have been purchased legally, Dean said.

Relatives of Long could not be immediately reached for comment Thursday. A former roommate described Long as “quiet, really really quiet" and prone to unusual behavior — like dancing alone in the garage to trance music — but said he never saw any signs of mental-health issues.

Neighbors of the home where Long lived with his mother recalled the police visit in April. Richard Berge, who lived around the corner, said he saw police cars blocking the street and saw officers standing across the street with a rifle.

Carol Richardson, who lives a few houses down from the Longs, said she heard yelling and banging before the police arrived in April. After Wednesday night’s shooting, she said, her son texted her saying: "I bet it was that guy.” She said there were other incidents involving Long. Her 19-year-old daughter, Morgan, said: “We always knew he had problems.”

Reports of a shooting first came in about 11:20 p.m. Pacific time Wednesday, and authorities arrived on the scene at 11:22 p.m., Dean said. After Helus was struck, the highway patrol officer secured the perimeter, Dean said.

Six off-duty police officers from other agencies were inside, Dean said. He said the parent of one person who was there told him the officers stood in front of her daughter to protect her.

Witnesses reported seeing smoke, but it was unclear if those were from smoke bombs, Dean said.

Two women wearing blankets leave the area near the Borderline Bar and Grill in Thousand Oaks, California. (Mike Nelson/EPA-EFE/Rex)

The shooting unfolded a little more than a year after a lone gunman opened fire from the 32nd floor of the Mandalay Bay Resort and Casino in Las Vegas, killing 58 people. The Sutherland Springs church massacre that killed 26 people followed just weeks later.

Many of those at the Las Vegas festival last year had come from California, and some at the venue in Thousand Oaks also said they survived that earlier attack. Chandler Gunn, 23, told the Los Angeles Times that when he heard about the shooting, he called a friend who works at the bar and was also at the Route 91 Harvest Festival targeted in Las Vegas a year earlier.

“A lot of people in the Route 91 situation go here,” Gunn told the newspaper after the Thousand Oaks shooting. “There’s people that live a whole lifetime without seeing this, and then there’s people that have seen it twice.”

The Borderline Bar describes itself as Ventura County’s largest country dance hall and live music venue. With a dance floor covering about 2,500 square feet, it is open until 2 a.m. five days a week. Authorities said more than 100 were inside at the time of the shooting. Scores of colleges lie within a 20-mile radius of the bar, including Pepperdine University, California State University at Channel Islands, Moorpark College and California Lutheran University, which has its own line dance club.

Pepperdine officials said that multiple students from the school were at the bar during the shooting. California Lutheran canceled classes “given the tragedy and uncertainties.”

While officials haven’t released the names and ages of those killed and injured, the combination of factors — a bar near colleges on a weeknight — suggested that many are likely in their late teens and 20s.

Matt Wennerstrom, who has blood on his shirt, talks to the media outside the Borderline Bar and Grill. (Mike Nelson/EPA-EFE/Rex)

Matt Wennerstrom, a regular at the bar, told reporters he saw the gunman open fire on employees working at the front of the bar.

“At that point I grabbed as many people around me as I could and pulled them down underneath the pool table that we were closest to until he ran out of bullets for that magazine and had to reload,” he told ABC.

During the pause, Wennerstrom, 20, said he and others threw bar stools through a window and helped people escape. He told ABC he was able to push “30 or 35 people through that window.”

Rochelle Hammons, 24, told The Post that she heard four shots before she was able to flee.

“Everyone got down on the floor," she said. "Everyone ducked and covered each other As everyone crouched down on the floor, I figured that my only chance would be to run out to the nearest exit. I saw the nearest exit, and I ran out as fast as I could.”

Content from Allstate This content is paid for by an advertiser and published by WP BrandStudio. The Washington Post newsroom was not involved in the creation of this content. Learn more about WP BrandStudio.