A Pokemon's Speed determines who goes first in battle. A Pokemon with 200 Speed will move before a Pokemon with 199 Speed.
Some moves have "priority". A move with a higher priority will move before one with lower priority. For example, if a Pidgeot with 300(just an example) speed went against a Deoxys with 301 speed, the Deoxys would normally move first. But if Pidgeot used Quick Attack, and Deoxys used Light Screen, Pidgeot would move first because Quick Attack has higher priority. If two Pokemon use a move with the same priority, the Pokemon who has more speed will move first. Example, Pidgeot and Mew. Mew uses Quick Attack, and so does Pidgeot. If Pidgeot or Mew has lower speed than the other, that one will move last.
If two Pokemon with the same speed use a move with the same priority, whoever moves first is determined randomly.