Both. But, if I have to pick one, it is a shotgun.
Here is why. At extreme close distance, one thing becomes the most important factor above all else:
THE ABILITY TO INSTANTLY STOP YOUR ATTACKER
No weapon can guarantee this. But, the shotgun will come the closest. A man shot with a handgun will often live 10 seconds before he bleeds out. While he is busy dying, he can be busy killing you. People shot with shotguns will tend to do this less often.
This is the most important consideration. All other things are secondary.