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.