At least 12 people were killed in a shooting late Wednesday at a bar in Thousand Oaks, Calif. Borderline Bar and Grill was holding its weekly event for college students.Published OnCreditCreditJenna Schoenefeld for The New York Times

THOUSAND OAKS, Calif. — A Marine Corps veteran who had served in Afghanistan fatally shot at least 12 people Wednesday night when he stormed a crowded country and western dance hall in Thousand Oaks, Calif., the authorities said.

The Ventura County sheriff, Geoff Dean, said that the gunman, Ian David Long of nearby Newbury Park, Calif., apparently took his own life after being confronted by officers responding to the Wednesday night attack. The .45-caliber handgun he used was purchased legally, but had been outfitted with an extended magazine.

The shooting came just over a year after 58 people were killed at a country music festival in Las Vegas when a gunman opened fire from a high-rise hotel room. There was an eerie parallel between the two shootings as some of the same people who emerged from the bar, the Borderline Bar & Grill, described having survived the shooting on the Las Vegas Strip.

Deputies had some interaction with Mr. Long the last few years, the sheriff said, including a reported disturbance at his home in April that prompted mental health specialists to talk to him. The health specialists, who talked to Mr. Long about his military service after suspecting that he might be suffering from post-traumatic stress disorder, determined that he was not an immediate danger to himself or others and that he could not be involuntarily taken to a mental hospital.

Witnesses recalled a chaotic scene at the bar, which was filled with hundreds of people, many of them college students: A gunman opening fire, first at a security guard, as patrons dropped to the dance floor, hid under tables and broke windows to escape.

Sheriff Dean said that at least six off-duty officers were inside when the gunman opened fire. A parent told Sheriff Dean that “they stood in front of my daughter” and protected her. Witnesses also told local news media about patrons in the back of the bar who broke out a window and helped a number of people escape.

Kerry Henzgen, left, and Kelly Griffin watched the procession for Sergeant Helus. “We know kids that were in there that got out,” Ms. Griffin said.CreditJenna Schoenefeld for The New York Times

The number of people wounded in the shooting on Wednesday was unclear, but the Ventura County Sheriff’s Office said about 22 people had been taken to various hospitals.

The sheriff, his voice cracking, identified one victim as Sgt. Ron Helus, who was shot when he entered the building.

“He died a hero because he went, he went in to save lives, to save other people’s lives,” Sheriff Dean said.

Country music was playing in the dimly lit bar when people first heard gunshots some time before midnight. Some said they had initially mistaken the sounds for firecrackers.

Sheriff Dean said Mr. Long first shot a security officer outside the club and then walked inside, turned to the right and shot “other security and employees” before starting to fire on patrons in the main part of the club.

“No idea what the motive was,” the sheriff said. “We don’t believe he was targeting people.”

“I just started hearing these big pops,” said a witness interviewed by a local television station.

Sheriff Geoff Dean of Ventura County said that the gunman apparently took his own life after being confronted by officers responding to the Wednesday night attack.CreditJenna Schoenefeld for The New York Times

Sarah DeSon, 19, a communications student at California State University Channel Islands, said: “I saw sparks going and smoke. There were smoke bombs going off next to me.”

Ms. DeSon described a stampede of people fleeing the club.

“I fell on my face,” she said. “I remember looking back at one point to make sure he” — the gunman — “wasn’t behind me.”

Chyann Worrell, a junior at the university, said she was at the bar to celebrate the 21st birthday of her friend Nellie Wong for a night of line-dancing with a live D.J. Shortly after 11 p.m., Ms. Worrell said, the gunman, wearing dark clothing and a dark baseball cap, drew his gun. He aimed it at a man near the front of the bar.

Ms. Worrell ducked for cover and heard a barrage of bullets. As she ran out of the bar, she said, she saw several bodies sprawled on the floor. Hours later, she had still not heard from two friends who had been with her.

One young woman inside the bar, Teylor Whittler, said the gunman appeared focused and did not appear to be targeting anyone in particular.

“I saw him shoot,” Ms. Whittler said, adding that someone had yelled, “Everybody get down.”

She said she saw him quickly reload his gun and fire again. “He knew what he was doing,” she said. “He had perfect form.”

Law enforcement officers on Thursday outside the home of the shooting suspect, Ian David Long, in Newbury Park, Calif.CreditRobyn Beck/Agence France-Presse — Getty Images

“People started running to the back door,” she said, and she heard someone shout, “Get out — he’s coming.” She then fled and heard another burst of gunfire.

Brendan Kelly, 22, helped several people escape from inside. “It’s your worst nightmare,” he said. “It’s terrible.”

Sergeant Helus entered Borderline with a Highway Patrol officer shortly after the first 911 calls, Sheriff Dean said. The gunman immediately started shooting at them, striking Sergeant Helus several times.

When the next group of officers entered the bar, they found Mr. Long dead in an office inside the club with an apparent self-inflicted gunshot wound.

Hours after the shooting, local law enforcement officers and F.B.I. agents arrived at the neatly kept suburban home in Newbury Park, west of Thousand Oaks, where Mr. Long lived with his mother. The home was cordoned off with red crime scene tape.

A neighbor, Tom Hanson, 70, said that Mr. Long was in middle school when they moved in. After high school, Mr. Long served five years in the Marine Corps, including seven months in Afghanistan, according to military records. He left the corps with the rank of corporal in March 2013.

Mr. Hanson described Mr. Long as an introvert who rarely left home. Sometime this spring, Mr. Hanson said he became concerned about shouting coming from the house and called the sheriff.

In addition to that interaction with deputies, Sheriff Dean said that Mr. Long was the victim in a January 2015 fight at a different bar in Thousand Oaks, and had received a traffic citation.

Copyright 2017 Content TiNYg RWT All rights reserved.

Want to change how you receive these emails?
You can update your preferences or unsubscribe from this list