Father-of-three Jasvinder Singh Bohgan was hit 10 times with the weapon by a thief at the Thorntons sweet factory in Belper, Derbyshire, Nottingham Crown Court was told on Monday.
Callum Allen, 31, of Cleveland Avenue, Draycott, Derbyshire, denies murder and two charges of burglary, one of them four months prior to the killing, and the other on the same date.
Mr Bohgan, 42, of Leicester, was found by two workers arriving for an early shift at the toffee factory on August 12, 2001.
Gaming machines
John Warren QC, prosecuting, said: "Mr Bohgan was discovered lying face up in front of his car, his head covered in blood. The men were sure he was dead."
The court heard Mr Allen, who had worked as a guard at the factory for Securitas between 1997 and January 2000, was unemployed and had broken into the factory to steal from gaming machines.
Mr Warren said that Mr Allen was later confronted by Mr Bohgan, who was making a sweep of the site on his rounds.
The prosecution allege Mr Allen, who had a crowbar and a hammer, struck the guard repeatedly and then fled, dumping the weapons in the nearby River Derwent.
Hit with hammer
Jurors heard that the hammer was later recovered by police and that DNA material on the item matched that of the defendant.
"He later told his boyfriend that he had hit Mr Bohgan about 10 times with the hammer," said Mr Warren.
"Then he said he threw the weapon in the river."
The jurors heard that Mr Allen had told police he had been watching films and drinking with friends on the night of the killing.
"He said that he had taken two ecstasy tablets and that it had made him drowsy and that he, in his words, was zonked out," said Mr Warren.
The trial continues.