The gunman who massacred 12 people at a country music bar in southern California on Wednesday night has been identified as an ex-Marine.

Ian Long, 29, opened fire on the Borderline Bar and Grill in Thousand Oaks at 11.20pm. Long had been cleared by mental health experts after an incident in his home in April, sheriffs revealed on Thursday morning.

He killed 11 people inside the bar and one of the first cops on the scene before taking his own life.

Survivors from the shooting said he looked ‘like he knew what he was doing’ as he repeatedly fired his legally purchased Glock .45 handgun.

As dozens ran for their lives, hid beneath pool tables and used bar stools to shatter the windows to escape, Long continued firing and also threw smoke grenades to confuse the crowds.

When the first police officers arrived at the scene three minutes later, Long shot one of them multiple times before shooting himself.

By the time SWAT teams arrived, he was dead. His body was found in an office inside the bar. The sheriff’s sergeant who was shot later died in hospital. He was Ron Helus, a 29-year veteran.

In total, 13 are dead; 11 people inside the bar, the sheriff’s sergeant and the gunman.

Long is a former Marine who lived in nearby Newbury Park. In April this year, deputies were called to his home amid reports of a disturbance.

Ian Long, 29, is the gunman who opened fire on Borderline Bar and Grill in Thousand Oaks, California, on Wednesday 

He was acting ‘irrationally’ and was ‘irate’ so police called in their mental health specialist. They cleared Long, deciding against having him committed, and left him at the home.

It is unclear if he already owned the weapon he used to commit Wednesday’s attack or if he bought it afterwards.

In addition to the 12 people he killed, ’10 to 15′ victims were injured.

According to survivors, Long was dressed in all-black, wearing a baseball cap, sunglasses and a mask covering the bottom part of his face.

He walked up to the entrance at 11.20pm and shot the bouncer before making his way into the venue. He then shot a young female cashier before throwing smoke grenades onto the dance floor and letting off rounds into the crowd.

The bar is popular with college kids because it allows under 21s in on Wednesday nights.  Those who were not old enough to drink had black X’s stamped on their hands.

Pepperdine University confirmed on Thursday morning that some of its students were among those in the bar. It is unclear if they were among those killed.

‘The University has determined that multiple Pepperdine students were on site at Borderline Bar and Grill in Thousand Oaks. At this time, the University is working to identify and provide support to those students.