Surveillance cameras have captured the moment a convenience store clerk shot and killed an armed intruder following a violent struggle.

Police said two masked men entered the store in San Francisco where 56-year-old Mark Kasprowicz was working behind the counter on Sunday night.

One of the men held Kasprowicz at gunpoint while the other went behind the counter and violently pistol-whipped him.

The store's surveillance cameras captured one of the men shoving Kasprowicz to the floor and striking him with one hand while grabbing cash from the register with his other hand.

Police said two masked men entered the store in San Francisco where 56-year-old Mark Kasprowicz was working behind the counter on Sunday night and attacked him

Kasprowicz could be seen bleeding from the head and cowering below as the assailant continued to grab the cash.

At one point, Kasprowicz quickly reached for a gun in a drawer next to the register.

The assailant then pistol-whipped Kasprowicz and tried to open fire but his gun appeared to jam.

Both assailants were caught on camera fleeing the store as Kasprowicz stood up from behind the counter.

Kasprowicz managed to fire one shot as his attackers fled.

One of the assailants collapsed and died about a half block from the store while the other man got away.

The store's surveillance cameras captured one of the men shoving Kasprowicz to the floor and striking him with one hand while grabbing cash from the register with his other hand

Kasprowicz could be seen bleeding from the head and cowering below as the assailant continued to grab the cash

Kasprowicz, who is an Air Force veteran, said his military experience helped him stay calm and survive.

'Instinct just kicked in,' Kasprowicz said.

'Fear and adrenaline kicked in together. I'm lucky to be alive.'

Kastrowitz said the experience will not prevent him from doing his job and he will return to work after he recovers.

He received about 12 stitches in his head at the hospital following the attack.

The name of the suspect who died was being withheld pending notification of next-of-kin, the Contra Costa County Coroner's office said.

Sheriff's spokesman Jimmy Lee confirmed an incident had occurred but did not release further details.