The incident happened at East Bay Firearms, located at 4049 First Street, on Sunday around 2:30 p.m, according to the Livermore Police Department.
The suspect, wearing a mask, gloves, and a hooded sweatshirt pulled over his head, entered the store acting suspiciously, said police.
Witnesses reported that the suspect, armed with a hammer, attempted to take a firearm. In response, the gun store owner fired two rounds, killing the man.
Authorities have identified the suspect as a 28-year-old man from Redwood City, but have not released his name.
The gun store owner is cooperating with the investigation, and police do not consider him a suspect, as it appears he acted in self-defense, officials said.
At the time of the attempted robbery, there were five customers inside the store. None of them was injured.