You've just slain the Lich King of Razuldoom and are fleeing for your life. The Lich King's army, however, is trying to kill you, constantly chasing as you desperately try to make it back to your means of escape. Worse yet, they're catching up. A door way is opened, the fighter rushes everyone through before closing it, and sealing himself in with the approaching hordes. His plan is simple: fight and die, buy as much time for the rest of the group to escape and make it back to deliver word of their success, to deliver word that there is still hope.
Seem familiar? I mean the specifics may not be, but the scene in general should. It is one of the methods used for heroic sacrifice, and can be a powerful story telling tool. It is often a way for a character who did a heel-face turn to die in an act of final redemption. Alternatively, for a character to show how much they care about their friends, sacrificing themselves to save everyone else. There are many ways for it to happen, but by and large it just means one person sacrifices their life specifically so someone (or multiple other people) can live. It's a great and powerful moment, that sounds like it'd be perfect to happen in a RPG right? Right. Problem is, they're incredibly rare in RPGs, and for a number of reasons. I'm not saying they're impossible, just hard, and to get them done you need to be forewarned about a few things.
Problem 1: The Setup
This is the only step the GM can really have an impact on, and even then, setting things up for this kind of desperation is hard when you don't have total control of the story. See, in books, movies, and comics the author has complete control. Often they will even have it planned at the beginning of the book who is going to die in this way, and they can shape things to bring it about from a very early point. In a RPG though, you don't have this control. The players play their characters, and that brings in an element of instability and lack of control. Maybe the knight doesn't fall for the elven princess, and thus feels no need to sacrifice himself for her. Maybe the mage finds a way to keep transport closer to hand, or saves a few spell slots specifically to aid in the get away. Maybe people just aren't as tired and beat down from the fight because they rolled well, maybe a lot of things really.
Above and beyond this, you have a structure issue as well. A lot of players, especially if you're a good GM, will trust you to not put them into a situation where they have to choose to die fighting or die running. Even if that isn't the choice for the group, a situation where someone has to sacrifice their character's life is generally considered bad mojo. I'm not saying it is always the case, but I've said it myself over a dozen times that the GM should try to avoid putting people in the decision of 'death or the left door'. It's a good rule, one you can break if you know it, but it also means that because of it, the players just may not see the situation. Or will have bad feelings about it, especially if there is a lot of campaign left and they particularly like their character and wanted to see more with it.
Problem 2: No Need For Sacrifice
Players are wily. There are no ifs, ands, or buts about it. Players will come up with some of the most ridiculous and remarkable plans when the heat is on, and they will do it just as often - if not more often - than they will freeze under that same pressure. This means that they're going to throw you curve balls, screw balls, any kind of thing they can, and, if you are doing your job right, this means your carefully constructed plan for epic sacrifice will just fall to pieces. Players will try the most insane of actions to try and survive these moments, and if the dice come down on their side, it will happen. This isn't even particularly a problem, especially as these insane plans are really fun to watch play out, but it does pose a problem for the ultra dramatic and serious 'heroic sacrifice' that you were going for with it.
Problem 3: Not On My Watch!
This is probably my favorite of the big three problems with heroic sacrifice, and something I reference a lot when I talk about SPTs (Standard Player Tendency). Standard Player Tendencies is exactly that, things that players do 'all the time,' and that RPG stories are full of. Your group may be good and not show many SPTs, it just means they're not standard players, but I've yet to see a group that doesn't hit at least some of the things on this list. The SPT for heroic sacrifice is exactly what I dubbed the title of this problem, "Not On My Watch." To explain, I'm going to use a couple of anecdotes.
In an online RPG I GMed for, I ended up taking over a scene. The premise was simple, a freshly frozen river, and a powerful warrior blocking the way. The PCs were confident that he could kill them all one on one, as he wanted to fight. But an attempt to rush him was also out of the picture, and they needed to beat this guy to finish their mission. I'm not saying this was the case, just what the PCs thought it was. So, anyhow, one of the players figures a way out. He's going to man up for the mission's sake. He walks out onto the ice to fight the guy, lures him into position, and then shatters the thin ice sending them both into the freezing water. His plan was to die for the mission. The reaction from the other players was immediate, and three of the four people threw themselves into the rushing, raging, and freezing water after their friend who was trying to sacrifice himself. Of those three, only one had the swimming skill, and that at the lowest rank. The best part is, the person who went under had made the series of insanely high rolls to survive (he had a lot of Stamina and swimming), so three people endangered their lives for nothing, just to stop a heroic sacrifice.
In another game, a PC was stopping to do the "I'll hold them off" bit that I opened this entry with. The other PCs immediately (once more forgetting the mission) turned and rushed back to help him fight. Suddenly the fight that they had known seconds before was death to face was something they would fight. They all went back to fight, and the guy started running again since there was no longer any point to it. The mission ended up being a failure, as they had given up their lead in trying to stop the one character from sacrificing himself to help them all out.
Now, in both of these situations, I think part of the problem is the view point that the GM won't kill everyone. In the first anecdote, I'm sad to say it was true, I didn't kill anyone. I let them get by with some stuff they thought of during an overnight break. The second one, they all died. I feel no regret for this either, it wasn't a case of bad GMing. Their choice wasn't "everyone dies, or one person sacrifices their life", but someone had chosen to be the hero and help them out more. The group, in response, went back and chose to die all as one. The result was the monsters caught up, and when they started running again it was simply too late. The dice didn't work out for them as needed, and they all paid the price for turning back to face impossible odds.
There are other reasons for it as well. Sometimes one or two people will go back to help, trying to increase the odds of everyone surviving. Sometimes multiple people will just come up with it at the same time. Sometimes it is in character, and sometimes it's just that everyone wants to be the hero. It is partly why people play RPGs after all, to be the hero and save the day. I've even seen one player call someone who was sacrificing their beloved character for the good of the group a 'Glory Thief'. Not cool in my book, but that was the justification both IC and OOC for going back to join them. They didn't want that person getting all the glory and the cool story treats when people discussed the game OOC later down the line.
So, just be aware of this. If you have someone try to do heroic sacrifice, be prepared for parts of, or the whole of, the group to go back and face death together. It is just something PCs do at times. Don't be afraid to give them the consequences of their actions either.
So, how do you do it then?
Honestly, there is no easy answer for how to do it, aside from talk to your players before hand. If someone seems like their character is going a little suicidal, ask if they'd like that chance. Ask the fighter, or just in general. Perhaps they'll come to you about it. But that really is the best way is to talk about it happening OOC before you bring it up IC. That way when it does happen, everyone involved is prepared. This step can be skipped, but I'd only recommend it if you really know your group.
Aside from that, the only way to stop number 3 is to just point out the consequences briefly. "If you go back, you will likely die as well ruining everything" is all you need. Say it once, if they ignore it that is their problem. They have chosen their actions, and they have done so while being informed. That is all there really is to it.
Like always, have fun with it. Don't get tied down to a script for how things have to happen. Let it flow out. It works a lot better that way.