The nice thing about a shotgun is that "close" counts. With a rifle or carbine, you need to hit something much dead on. A shot grazing the side is not likely to stop the attacker.
A shotgun, because it its scattershot nature, means that if the center of the column grazes someone's side, they still take 3 to 5 hits, some of which in a more damaging area.
A shotgun is also easier to handle in a panic. If you at least aim down the bore, you should be close to your target. A rifle, you'll have to find the sights and make sure you're close to center-of-mass on your target. If you've ever shot in a stressful situation (and by that I mean anything that gets your heart up, something as simple as shooting with a shot timer or at an IDPA match), you know how quickly your training can go out the window.
A lot of folks talk about bird shot. It will leave one nasty looking, but you'd better be CLOSE to your target, and I mean "smell his breath" kind of close, for that to really stop him. The birdshot scatters pretty quickly, losing a lot of its stopping power.
Personally, I have a Saiga 12 ga semiauto with #1 buck loaded in it (I live in an apartment and wanted to cut down the "missed target" penetration risk), and additional magazines with 00 buck ready to go.