When multiple paths exist to the same prefix, BGP selects one using a decision algorithm. The router compares paths step by step until one wins.
The order (simplified):
Highest LOCAL_PREF Shortest AS_PATH Lowest ORIGIN type (IGP < EGP < Incomplete) Lowest MED (only for routes from the same AS) eBGP over iBGP Lowest IGP cost to NEXT_HOP Oldest route (stability) Lowest router ID
Most decisions happen in the first steps. LOCAL_PREF for policy, AS_PATH for path length, then increasingly minor tiebreakers.