I'm not totally sure, but I believe the story battle ends after Ultimate uses his normal repertoire (Quake2, a physical attack, Ultima Beam), while the optional battles end after roughly 3-5 turns. This seems to be a random determination by the AI. Damage plays no real role in the escapes, other than the 80,000+ damage forcing him to flee to the final location.