There must be 50 ways to save that party!
Let them slip out the back, Jack,
Make a new plan, Stan,
no need to destroy, Roy,
just listen to me…
In event of an immanent unacceptable TPK roll 1d8 on each table.
Foes
1. capture them
2. flee
3. parley
4. turn on each other
5. become distracted
6. change sides
7. surrender
8. are defeated by a miracle. (Stop. Do not roll on because.)
because
1. somebody the party once helped arrives*
2. an old enemy of the party arrives*
3. an enemy of the foes arrives
4. a powerful supernatural entity intervenes
5. an unforeseen disaster occurs
6. they mistake one of the party for somebody else
7. they have a change of plans
8. reroll.
* substitute a mysterious stranger if the party has no plausible old enemies or allies.
Note that in many games TPKs are entirely acceptable, or acceptable under certain circumstances. This is just for the times when a GM wants to stop a TPK in progress without fudging the dice.