A gunman who killed 12 people in a mass shooting at a bar in California has been identified as a former US Marine.

Ian David Long is believed to have killed himself late on Wednesday at the Borderline Bar and Grill in the city of Thousand Oaks.

A local sheriff said the 28-year-old ex-Marine had mental health problems and was known to authorities. 

Ventura County Sheriff Geoff Dean said his department had several dealings with Long, including a call to his home in April when deputies found him acting in an irate and irrational manner.

HeraldScotland:

He added that mental health crisis team was called at that time and concluded that Long did not need to be taken into custody.

Twelve people, including a sheriff's sergeant, were killed in the shooting.

Ten others were also shot and wounded.

Sergeant Ron Helus responded to the scene and was shot after he entered the building.

He died at a hospital early on Thursday.

The first reports of shots fired came around 11.20pm local time at the Borderline Bar & Grill in Thousand Oaks, which is about 40 miles west of Los Angeles.

The bar's website said it hosts College Country Night every Wednesday.

Police said hundreds were inside when the shooting occurred.

Tayler Whitler, 19, said she was inside the bar when a man walked in with his face partly covered by something resembling a ski mask, opened fire on a person working on the door, then began to shoot people at random.

"It was really, really, really shocking," she told KABC-TV as she stood with her father in the Borderline car park.

"It looked like he knew what he was doing."

HeraldScotland:

It has been "quite some time" since there was a shooting of any kind in Thousand Oaks, a city of about 130,000 people around 40 miles west of Los Angeles.

Nick Steinwender, student union president at nearby California Lutheran University, rushed to the scene when he heard about a shooting at the bar where he knew friends and fellow students were.

"It was chaos, people jumping out of windows, people hopping over gates to get out," Mr Steinwender told KABC.

He said he heard from people inside that they were hiding in toilets and the attic of the bar.