In the game, the action order is determined via the participating Pokémon's action time, a value that acts as a wait timer and determines when a Pokémon will have its next turn. Increasing a Pokémon's action speed is equivalent to decreasing its action time, and vice versa.
So there is an action clock in the works. Every Pokémon in the encounter has a number that counts down to 0 and then awards a turn, then the timer resets. There's a lot of nuance with this type of thing so I will attempt to break it down step-by-step:
How is the first turn decided?
Each Pokémon begins the battle with their default action speed, which is determined by their Speed Stat, as shown in the table below:
+--------------+-------------------+
|Speed Stat |Default Action Time|
+--------------+-------------------+
| 15 or lower | 14 |
| 16 - 31 | 13 |
| 32 - 55 | 12 |
| 56 - 88 | 11 |
| 89 - 129 | 10 |
| 130 - 181 | 9 |
| 182 - 242 | 8 |
| 243 - 316 | 7 |
| 317 - 401 | 6 |
| 402 or higher| 5 |
+--------------+-------------------+
If the number 0 is reached simultaneously, turn order is awarded first to the Pokémon that hasn't taken a turn the longest (not during the initial turn), then the Pokémon with the highest Speed stat, and then the player's Pokémon the case of a tie.
There are special cases, however. If a player back-strikes a wild Pokémon, they start with their timer at 0 and the wild Pokémon's timer at 1. Conversely, if a player encounters a Pokémon, runs, and then rebattles that same Pokémon, that Pokémon gets their counter set to 0, and the player's counter set to 1. If both of these happen simultaneously, the back strike takes priority, and the player goes first.
When a Pokémon faints, how is the next Pokémon's turn determined?
In trainer battles, the Pokémon being sent in inherits the fainted Pokémon's elapsed time. This is one of the most interesting sentiments. Let's say you have a Pokémon with a default action speed of 14 and another with a default action speed of 5. Your Pokémon with an action speed of 14 gets KO'd by an opponent when it's timeline was on 9. Sending out the Pokémon with action speed of 5 will grant it a turn immediately (14 - 9 = 5). Conversely, if it were the other way around, and your opponent had a Pokémon with a low default action speed, it is likely they'd be able to attack you again, maybe even twice with Agile Style.
How does using items and Strong or Agile Style moves effect the timeline?
This is also very interesting. First off, Items typically do nothing, your time gets reset as normal. However, there are a few items that have a direct effect on the timeline, and they are the stat boosting items. They consist of:
- Aux Power
- Aux Guard
- Aux Powerguard
- Aux Evasion
- Dire Hit
- Choice Dumpling
- Twice-Spiced Radish
- Swap Snack
Using these items during your turn add 3 to the default action speed when it is reset. This means a Pokémon with a default action speed of 14 must now wait 17 before receiving another turn.
Furthermore, using a move in Strong Style also adds to the default action speed for next turn, therefore increasing your wait on the timeline. The increase is move dependent, and ranges from 5 to 8, and doesn't add anything to certain moves (such as Teleport). There are some moves that also make you slower just by using them, such as Dark Void or Hyper Beam.
Using Agile Style moves is less straightforward, however. If using a status move or a move used on yourself, your default action speed receives a decrease for next round. However, if using an Agile style move against an opponent, their action speed is slowed, as they receive more time to wait as a result of being hit. This means an agile move that hits an opponent will only move one opponent down the timeline in an encounter with multiple opponents. Furthermore, many status moves used on oneself naturally decrease their timer by a small amount, and moves that typically can cause flinching or would normally lower a target's speed add more time for an opponent to wait without needing to be Agile style. When they are Agile Style, the effect is increased. Examples of such moves are Rock Slide and Bulldose.
You can find the full list of moves by action speed modification here.
That about sums it up. :P
Source
Hope I Helped!