Jeff Lupak, 45, said he felt no pain after the accident in Bismarck, North Dakota, but was convinced he was going to die.
Even doctors were amazed that he was still alive when he was rushed to hospital where an X-ray showed just how far the nail had penetrated into his skull.
But incredibly the nail had missed all the major arteries and was lodged between his brain’s left and right hemispheres.
Despite feeling no pain Mr Lupak, a father of three, was told the seriousness of his injury.
One doctor told him: ‘Leave it in, it’ll rust and you’ll die of infection. Pull it out and you’ll bleed to death.’
A surgical team led by neurosurgeon Dr Eric Nussbaum at the National Brain Aneurysm Center in St Paul, Minnesota, took more than an hour to remove the nail.
Dr Nussbaum said: ’He was very lucky. I mean this is a potentially fatal injury depending on what structures it hits on the way.’
Mr Lupak was working on a construction site in Bismarck when he asked a colleague to hand him a 16 gauge nail gun.
As he grabbed the gun he heard it go off and felt a stinging sensation in the back of his head.
The co-worker began shouting that Mr Lupak had been shot with the gun – but Mr Lupak said he only felt a slight pressure in the back of his head.
After being taken to a hospital in Bismark he was flown to St Joseph’s Hospital in St Paul where neurosurgeons were waiting to carry out an operation to remove the nail.
His wife Kim was taken to the hospital where she was given an X-ray showing the nail protruding into her husband’s skull.
The operation proved a success and Mr Lupak is recovering in hospital with his only problem moving his left toes and ankle.
Doctors have said he will make a full recovery. Mr Lupak, a construction worker for 28 years, admitted he was lucky to be alive.
‘Somebody was looking out for me,’ said the husband and father of three daughters.