I also agree with Ranger REG's suggestion, but I'll throw out a counter-point.
There's something poignant about having the pcs triumph against their own particular challenge and then look around and see most of their army vanquished, or the the city they're defending gutted and burned. Its all down to the needs of the individual campaign or story, and I say if you're going to handwave a story, handwave an interesting one. Having the pcs win the day makes a great bang-up ending, but having them win the battle and lose the war sets up a lot of challenges down the line.
There's something poignant about having the pcs triumph against their own particular challenge and then look around and see most of their army vanquished, or the the city they're defending gutted and burned. Its all down to the needs of the individual campaign or story, and I say if you're going to handwave a story, handwave an interesting one. Having the pcs win the day makes a great bang-up ending, but having them win the battle and lose the war sets up a lot of challenges down the line.