Whoever got the last attack of opportunity attacks first
From the combat rules, we know that attacks of opportunity interrupt the flow of actions:
An attack of opportunity “interrupts” the normal flow of actions in the round. If an attack of opportunity is provoked, immediately resolve the attack of opportunity, then continue with the next character’s turn (or complete the current turn, if the attack of opportunity was provoked in the midst of a character’s turn).
And are resolved first based on what action provoked the attack of opportunity, as shown on this post from Jason Bulmahn (by then, Lead Designer at Paizo):
I am kinda amazed that this is still raging on. I have skimmed the posts from my ruling till now and most of them seem to be focused around a gamist argument, which I can understand. The time issue really is just to keep matters simple (as many have pointed out). Technically, the AoO occurs as the event that provokes it is taking place, but since we can't have "middle ground" conditions, they are pushed to before to keep things straightforward. This is the only way it makes sense for spellcasting, movement, and, in this case, standing up and trip.
So, if an action provokes an attack of opportunity, the attack of opportunity is resolved before the action that provoked it. If multiple actions provoke multiple attacks of opportunity, then you will probably have to write down which provoked and which are attacks of opportunity for ease of controlling the situation. That might not be necessary when the combatants can only make one or two attacks of opportunity per round, unless they both have high dexterity and combat reflexes.
Example: Two characters are fighting, character A attacks character B with a ranged weapon at melee range and provokes an attack of opportunity, character B then attempts to disarm character A and also provokes another attack of opportunity because character A has improved unarmed strike and can threaten with his feet. This is the apparent order of events:
- 1: Ranged attack;
- 2: Disarm attempt;
- 3: Kick to the face.
But this is the order things are actually resolved in the game system:
- 1: Kick to the face;
- 2: Disarm attempt;
- 3: Ranged attack.
Should the kick to the face put character B unconscious, his disarm attempt automatically fails because you cannot act while unconscious. Should the disarm attempt be successful, the ranged attack fails because the character now has no weapon, though he could draw another weapon using his move action now.
Another example of this is the trip FAQ, which states that a character who is standing from prone and provokes an attack of opportunity, cannot be tripped again because he is technically still prone when the attack happens.