An adventure is like a path winding up a mountain. Some of the sections are up a steep slope with the characters wheezing and slogging and working hard every minute and other bits are more relaxed, calm, perhaps even beautiful with a little bit of sightseeing and character growth along the way. The conclusion is right at the top of the mountain when the pacing has peaked and that last stretch of path is generally the hardest. Not always, as its a roleplaying game and not a movie and therefore you've got more flexibility with pacing, but at its best it gets tense and the stakes go up before the end.
The trick is ensuring that the game gets to its rightful conclusion. This is a tricky thing to do because the right conclusion isn't strictly about what you think is best and so you can't just rely on your own beliefs.
If you don't have the time to prepare for your ending because you're improvising it or the players have changed it up within the session you're currently running, then you'll need to go with your gut but pay a lot of attention to what you're hearing. If your players are getting really excited about setting up an ambush to take out the enemy, then consider letting it at least be partially successful.
Maybe it'd be too short and flat an ending to just let them snipe the Big Bad or maybe you know that the enemy has already been tipped off due to player actions or the set-up just wouldn't be conducive to their plans, but its often easy to make a few simple changes to let them get something out of their ambush. If their actions have built up to it, it would be flat for them to get nothing out of their efforts.
Especially as a good ending in any story is based off what the protagonists are doing and how that interacts with the antagonist's goals (or the threats' actions in the case of a non-sentient enemy). The players are always in control of the protagonists of the piece. Always. Other characters can be important and they can influence things but just like you'd be annoyed if you saw a Bond movie where some other character took care of the major plot threads for Bond, so will your players be annoyed. Hell, they'll be even more annoyed because its their spotlight you're taking away from them.
If you have the path skip right around their actions, therefore, they'll be irritated.
Having said this, if you've got the time to think about it you might be able to craft an even better ending by making more of their actions count. If they tipped off an informant and the enemy reacts accordingly, then that's good. If they scare someone into being an informant from the opposition due to their blundering, then that's even better. Cause and effect. Consequences. Not that you should string your players up by their necks for every mistake but the more you can tie in earlier actions with later outcomes the better.
So if you have the time then think about what the main characters have been doing. What choices have they made? Who have they been talking to? How did they talk to them? If they've put in a lot of effort to talk down the enemy, then even if you know that's an impossibility it's still worth letting that matter. Both on the thematic level of having to deal with someone who's too stubborn to live and on the level that perhaps the enemy is willing to discuss things over a trade in bullets - each shooting at the other when they get the chance while they talk it over. Sure, the bad guy doesn't get talked down but the players figure out a bit more about his motivations and his actions. They at least earn a more complete picture than they would have gained if they hadn't tried to talk him down.
Sometimes it can help to plot out all of the players' major actions if its been a particularly long adventure or if the campaign itself is coming to a close. Identify any loose plot threads and see if they can be resolved before the main action. It might be impossible to tie them all off as a campaign can quickly gather up a lot of partially completed plots and suggestions of further adventures, but perhaps there's a few main ones that can be dealt with.
Romantic interests, missing parents, an unexplained assassination attempt, that can be revealed to them beforehand. See if you can find a way to fold these through the main plot. A romantic interest is kidnapped and professes their love when rescued. Information on that missing parent comes up when they go to speak to their police contact about the nemesis. Perhaps their nemesis even reveals the information to try to distract them off their trail.
"Hey, your mother was killed by the police commissioner to get you to back off on the Macey Case and he's about to retire and move to Tahiti. You can track him down now or you can chase after me. Your choice."
Be prepared, though, for the above gambit to lead to a player character running off at the last minute if they're not suitably motivated to stick around. If so, make it clear to the player that their character won't be involved in the main event if they chase that lead and ask the player if there's anything the plot can do to keep them sticking around. If they insist, let their character ride off into the sunset (the villain's success) and contrive a way for another person to get involved. Its all good. If a character can die before the main event, they can get lured away.
In truth, your best bet is to know your players and what they love. They are your audience AND your co-writers. Its important that you know what they would love to witness as your audience and what they would want their characters to have to deal with. If your audience hates moral choices and always avoid them in-game, then don't include them even if you love them.
If your players have already had reason to become suspicious of you for taking the ending out of their hands and dragging them along your own path, then you'll have some making up to do. Take all the more heed of their plans and see what you can do to really help the players craft their own endings. Trust is something that takes time to set up. Once damaged, it takes all the more time to repair. But don't worry. Once you've regained their trust they'll be less resistant and you'll all have a more enjoyable time of it.
Well, that's been my experience of it anyway. You guys have any advice to add?
The main Endings article (and all the various links) can be found over here.