One game i ran my players waltzed into a hill giant lair and got rocked. It should have been a cake walk but they just handled it wrong...they divided their attacks and some were slow to engage and the high initiative rouge went bounding into the middle of a pack of hill giants and got smacked. TPK.
By this point of the game we had invested well over a year of real time. Some PC's had died in the game but for the most part the group was a cohesive whole. And then it was done. These heroes of the land who had literally gone to Hell and back were killed in a guard room.
I had established an angelic guardian to the region as an NPC. She was there really just to be cryptic and an info drop once in a while. I never imagined I'd use her as a deus ex machina but that is exactly what i did. I had her reset time and she let the players know that she did and it restarted them right before entering the guard room. It worked great. The players had no problem with it because there was a an internal consistency to what happened that made sense in the story, the NPC was punished by "a higher authority" for such a grievous abuse of power and was more or less removed from the story and the players felt a great guilt that a high price was paid by all involved. So my game kept going and my players got some in game character motivations.
I was a little scared about how it would go over but it was a satisfying resolution. I have found that if there is an in game/story reason players are very forgiving. It is defiantly a one time a campaign thing.