Police said they were called to the El Camino Real bar at 37667 Niles Blvd. around 1:05 a.m. for a report of a shooting.
Upon arrival, officers learned that a man got into an argument with the bar's security guard earlier in the night and was asked to leave.
The man went home, retrieved a gun and re-entered the bar around 1 a.m. and began shooting at the guard, firing several rounds, according to police.
"Miraculously, neither the security guard nor any of the 30-something patrons inside the bar were struck by any of the bullets," police said in a statement.
The guard chased the shooter into the parking lot and detained him until police arrived.
Police said officers arrested the gunman, identified as 31-year-old Miguel Vargas of Newark, on suspicion of attempted murder. Officers located the gun nearby, police said.
In a statement, police credited the bar's security guard for his bravery in stopping the suspect.
"We are very lucky that no one was injured in what could have been a very tragic event," police said.