The man, who was working for mattresses and bed bases maker Sleepwell (NZ) Limited, was awarded $15,000 reparation following a WorkSafe investigation.
Sleepwell, appearing in the Manukau District Court yesterday, was also fined $250,000 over the incident.
The incident took place in September 2019 at the company's South Auckland plant after a worker went to free a coil hose that connected his nail gun to the air supply line when the gun recoiled, firing a nail into the chest of the victim who was walking behind him.
The nail, which was lodged into the worker's heart, had to be surgically removed.
WorkSafe's area manager Danielle Henry said the victim was "lucky to be alive".
"His ordeal could have been avoided if the company had adequately identified the risks of using nail guns and implemented clearly marked exclusion zones– areas out of bounds to other workers.
"There was a real risk that other workers could come into contact with an operator's nail gun, and that is exactly what happened, so clear exclusion zones should have been marked out around work-stations where nail guns were in use."
Henry said WorkSafe's investigation also found a number of other issues at the factory.
"Nail guns weren't regularly checked to ensure they were fit for purpose, and workers were not being adequately trained", she said.
The victim was unable to work for three months following the incident.
Sleepwell was sentenced under sections 36(1)(a), 48(1) and 48(2)(c) of the Health and Safety at Work Act 2015.