It's actually a part of my game I put a decent amount of thought into.
If I'm using normal intelligent enemies for opposition (in other words, not brainwashed, enspelled, frenzied, etc.), they almost always try to flee if the fight turns badly against them.
If they're disciplined and loyal troops, they're more likely to stand and fight to the end, especially if well led.
If it's a fight between "civilized" enemies, and both sides have a reasonable expectation of being allowed to surrender and being tended to if badly wounded and disabled, they're also less likely to flee, and instead will put up a fight for a while even if it's hopeless to satisfy the demands of honor, and then surrender.
If they're well trained and fanatical (for example, elite troops serving some kind of evil cult) they'll not only frequently fight to the end, but will go to great lengths to avoid capture - suicide to avoid being taken prisoner while wounded, finish off wounded compatriots or drag the fight out to ensure any wounded bleed to death before killing themselves, etc.
Also, at times when I feel a morale roll of some sort would be a good idea and when the enemies are fighting at the behest of some authority figure (even if that figure is not around at the time) I'll often use the following mechanic: In order to break from the fight or disobey orders, the person fighting must make a Will Save vs. a DC equal to 10 + the Diplomacy or Intimidate modifier of the authority figure, +/- circumstance modifiers. (which depend on such things as the proximity of the authority figure, how likely they are to be able to punish the underling, their reputation for either fairness and wisdom or cruelty and capriciousness, and so on)
I'll also frequently use a similar mechanic to resist the PCs attempts at Intimidation or Diplomacy when the person they're trying to use those skills on is under contradictory orders from their leader - I usually just do it as an opposed check, though the absent leader in that case definitely gets a notable circumstance penalty.
Another thing I've had fun with a few times at the end of combat - and which always seems to throw the players for a loop - is having the badly beaten opposition (or perhaps the opposition's leader) rally for one more hard push aimed at taking down one of the PCs, and then holding his life hostage to try to either negotiate something better than a total defeat, or allow at least some people to get away freely.