Summary
So, you went too hard on your players. Or maybe they didn’t make the best decisions during combat. Either way, Total Party Kills is a real possibility inDungeons & Dragons,and though it’s something most DMs will do everything in their power to avoid, it can still happen, ending the story earlier than expected.
That said, it is possible to circumvent a TPK and allow things to continue, or you’re able to just continue a new story. From retcons to resurrections or allies, there are a few ways to ensure your party’s story won’t end with a group of Goblins laughing at their corpses after beating them. After all, the show must go on.

6Retcon
Retconning doesn’t have the best rep when it comes to D&D. The idea is to live (or die, in this case) according to your choices, right? However, there’s one particular scenario where this might be valid:how balanced was the fightthat resulted in the TPK?
There’s no shame in messing up difficulty, as it can be a hard thing to pull off. If you accidentally went too hard on the players, and they didn’t even have a chance to win the game, it’s okay to say you made a mistake and ask if they want to re-do the last encounter. One balancing mistake shouldn’t cost everyone’s beloved characters, after all.

All that said, if you notice you’re going too hard, but the fight isn’t over yet, don’t be afraid to ‘forget’ certain abilities and go a bit weaker on the players by being a bit dumb in your tactics.
5NPCs To The Rescue
Deus Ex Machina
Is there any relatively powerful NPC that could just appear during the fight in a way that doesn’t feel super forced? From a previous ally they met in the area to the warlock’s patron or cleric’s deity, someone can step up or send extra help to the players.
Just make sure things flow a bit organically as to who is showing up to help them. And while an NPC they like would be a fun savior, it’s also okay to have a few random people to help if it makes sense.

For example, if the fight is taking place in a city, the extra muscle could simply be a few guards who heard the commotion and decided to investigate. It could even be a third party that will attack everyone, so the players can use this to their advantage, such as a fight in a dungeon being interrupted by a wild Owlbear that will attack both the players and the baddies (you’re able to focus on the baddies first if you want to make things easier, though).
4The Baddies Don’t Actually Want Them Dead
They Can Find The Players Useful Or Something
Not every antagonist is a murderous monster who will kill everyone in their path. They can have a moral code, find some utility in leaving the party alive, or even have a personal relationship with one of the player characters, which prevents them from being overly aggressive to the player character and their friends.
Regardless of whether one of those or something else is the reason, bad guys can opt to cause non-lethal damage when knocking someone to zero hit points, just like players can.

Thus, they can choose to leave them all unconscious on the ground and leave, or they can capture the heroes, allowing you to kickstart a prison break session to escape the villain’s house, dungeons, orwherever they keep prisoners- that’s up to you.
Keep in mind that a TPK only happens when everyone dies. If everyone is down, they can still survive their death saving throws, and the story can very much continue after they get stabilized by themselves and go through a short rest to heal themselves through their hit dice. They can then revive those who failed their saving throws, or these players can just create new characters.

3Resurrection
If You Die, Walk It Off
In D&D, there are a lot of ways to cheat death. Between many spells, magical items that revive people, or powerful NPCs who can just do that, you can have someone bring them back to life. It can be an ally NPC or the baddy who finds the party useful, among other things. The point is that they can return.
You can even do that while still creating consequences. For example, the party can be resurrected years after their death, with the world being different from how it used to be. Maybe the villain is now even more powerful as they have accomplished their goal. You can also change their allies' current situation, such as having them killed or changing sides, among others.

They Can Revive Themselves
Death is not necessarily the endin D&D, as the campaign can simply continue with this bunch of corpses - or souls, as you’ll see. There are a few ways you’re able to go about it, but our first recommendation is to have them stay as some form of vengeful spirits - you can give them stats from the Reborn lineage and continue from there.
Our other suggestion would be a mini-arc in your world’s dead domain, as they have to find a way back to the land of the living by themselves, whether it means they’ll revive after leaving this place or continue among the living as souls until they’re properly resurrected. Either way, a group of dead people can work in D&D.
1Create A New Story With These Deaths As Consequence
Ask Them What They Want
As much as we love helping out with our suggestions, there are a few people you should talk to when a TPK happens: your players. They might be actually okay or at least accept the fact that a TPK just happened and are okay with starting a new journey.
And if both you and your players want to continue the current plot, you can use an idea similar to what we said in our Resurrection entry, where the villain succeeded due to the heroes' deaths, and now the new heroes have a deadlier world to venture through.
It’s also a perfect moment to turn NPCs into PCs if the players are into the idea. For instance, the fallen fighter’s NPC brother can now be played by the fighter as they seek revenge on the BBEG for killing their sibling - having the player fight the same villain for their previous character’s death is pretty meta, too.