If both Pokemon faint during the execution of the same move, the following steps are performed in order. Whichever Pokemon goes to 0 health first is considered to faint first, and will lose in case of a tie where those are the only Pokemon left.
- If the user is attacking with Self-Destruct, Explosion, Final Gambit, Misty Explosion, Mind Blown, or Steel Beam, the damage to itself happens first, ensuring that it will not win a tie.
- Perform the actual damage from the move, against the target. If the move has multiple targets, and one of them is the user's teammate, that damage is computed first, then each of the opponents takes damage in right-to-left order from the user's perspective (left-to-right from the opponent's perspective).
- If the move is Flame Burst, perform the extra damage to the target's teammate.
- Apply retaliatory damage to the attacker from Rough Skin, Iron Barbs, and Rocky Helmet (along with a bunch of similar "retaliation" effects that aren't relevant here since they can't possibly result in a Pokemon's HP changing).
- Apply all faints that happened so far to Pokemon currently at 0 HP. If the target fainted and had Destiny Bond in effect, or if they had Aftermath, those now get an opportunity to apply.
- Apply recoil damage.
- Apply retaliatory damage from Jaboca Berry/Rowap Berry.
- Apply self-damage from Life Orb.
You'll notice that steps 4-8 only ever inflict damage on the attacker, so this simplifies as "In the case of a double KO, the attacker wins unless they were using a suicide move, or Mind Blown/Steel Beam which are lumped in with the suicide moves instead of the recoil moves."
The alternative possibility is that all remaining Pokemon faint during end-of-turn effects. In that case, the order of steps is as follows. If the Pokemon are subject to effects in different steps, the earlier step happens first, and the Pokemon that faints in that step is the loser. Meanwhile, if they both faint in the same step, processing within each step is done using speed order. Thus, the faster Pokemon faints first and loses, unless Trick Room is in effect, in which case the slower one loses. This is particularly noteworthy for step 10, Perish Song, where it's likely to come up with reasonable frequency.
1. Sandstorm/Hail damage
2. Future Sight/Doom Desire
3. a single step comprising all of Black Sludge, pledge sea of fire, and G-Max moves like Charizard's that work like the sea of fire
4. Leech Seed
5. poison damage
6. burn damage
7. Nightmare
8. Ghost Curse
9. Bind/Fire Spin/etc.
10. Perish Song
11. Bad Dreams and Sticky Barb