The California man who killed a dozen people at a bar packed with college students was a former Marine who may have been suffering from PTSD, the Ventura County sheriff said.

Ian David Long, 28, who lived in nearby Newbury Park, unleashed a hail of bullets at the Borderline Bar & Grill in Thousand Oaks late Wednesday, Sheriff Geoff Dean told reporters.

He was armed with a .45-caliber Glock 21 handgun that he had legally purchased in Simi Valley, as well as a “smoke device,” he said.

The gun — which in California may hold 10 rounds in the magazine and one in the chamber — was fitted with an extended magazine, which is illegal in the state.

“We do not know at this time how many rounds were actually in the weapon or how many rounds the magazine could actually hold because it’s still being processed as part of the evidence,” Dean said.

Long drove to the club, walked up to the entrance and gunned down an unarmed security guard standing outside, Dean said. He then walked inside, turned right and shot other guards and employees.

Long then opened fire inside the bar, where he exchanged shots with Ventura County Sheriff’s Sgt. Ron Helus and a California Highway Patrol officer. Helus died later at a hospital.

When authorities entered the bar later, they found Long dead inside an office next to the entrance. It was unclear if he had reloaded his weapon during the assault.

“We believe he shot himself,” said Dean, adding that the shooter’s motive was unknown.

“We don’t have any other details to confirm an exact chronology about what happened. We’ll provide that to you as we bring all our witness statements together and we feel more comfortable about talking about that,” Dean said.

Long was on active duty with the Marines from August 2008 to March 2013, according to the Department of Defense.

His handgun was designed to hold 10 rounds plus one in the chamber — but the extended magazine, which is illegal in California, held more bullets, Dean said. The exact number was unclear.

Dean said his officers had several interactions with Long, including an April call to his home.

“We’ve had several contacts with Mr. Long over the years, minor events, a traffic collision,” he said. “In April of this year, deputies were called to his house for a subject disturbing. They went to the house, they talked to him. He was somewhat irate. Acting a little irrationally.”

Mental health professionals sent to evaluate him concluded he did not need to be taken into custody, he said.

Long also was the victim of a battery at a local bar in 2015, the sheriff said.

The sheriff also said there were six off-duty police officers from various agencies at the Borderline at the time of the attack.

Dean said a mother recalled that the cops stood in front of her daughter to shield her from the gunfire.