Man... I'm gonna be unpolular.
I've carried a shotgun in harms way a bit. I've seen the psychological effect and I have a nostalgic respect and love for the platform.
That said, it is not the best at anything... almost.
Against people:
Up close at 3 to 15 yards I still want a semi-auto rifle. A shotgun with good ammo is (up close) basically rifle level accuracy. Capacity is limited. Recoil is more. Follow up shots are inhibited. As distance increases the shotgun is 8-9 pellets that are basically very poorly ballistic .32 to 9mm at handgun velocities. At the same time they penetrate further in intermediate barriers (ie: walls) and offer additional chances (projectiles) to hit things unintended. If they do hit the target they can be very effective... and not. Jim Cirillo talks about this in his books and there are numerous stories to back it up. The shotgun isn't the 100% stopper that many would have one believe.
Rifle rounds are devastating. Not only that, to my knowledge we've never had a torso shot on my department that has exited the body with a .223. It penetrates intermediate barriers such as drywall like a handgun, but with the right round will punch right through a vehicle. This is why some very well respected tactical teams have gone away from the 12ga to the .223 with good ammo. The other thing is that argument about versatility with the shotgun. The complicated select slug process is simplified with a rifle... new mag in... rack the bolt.
For law enforcement I strongly believe that the shotgun has hit its apex and is fading, but it isn't dead. It is becoming a niche weapon for the few things it truly is "the best" at... and to me it is two things:
1. The people who have to use it.
If politics don't allow a militaristic rifle, or one hasn't been able to be rifle certified to carry one for their work but they have access to a shotgun... well... that's a great tool. Maximize it by zeroing the specific shotgun to the specific ammo (buck and slugs) used and get good so the trifecta of gun/ammo/user is a known commodity.
2. Animals.
Zanezville. If you aren't familiar with the Zanezville incident you should be. In that case I'd very much rather have a 12ga with Federal Deep Penetrators than any of those AR rifles. This is the single biggest reason I believe the shotgun still has serious relevance in law enforcement. It's not just that incident either... one can look at lots of incidents involving animals in different jurisdictions to see where having access to animal-specific ammunition is beneficial.
One might argue breaching, but most cops aren't trained in it, won't use it for that, and so I disregard it a bit... though it's certainly a valid choice for those who are trained in it.
For civilians as opposed to law enforcement, I would add the advantage that it's less likely to destroy eardrums in houses, and while manually-operated shotguns are harder to learn effectively (I've trained a decent number of people to use one) they are more forgiving of a lack of maintenence. The drawbacks still apply.