The MED attribute equals the metric used by an IGP. After the MED attributes of routes are set, an EBGP peer selects the route with the smallest MED value for the traffic that enters an AS if the other attributes of the routes are the same.
If the router running BGP obtains multiple routes from different EBGP peers and these routes have different next hops but the same destination, the BGP device selects the route with the smallest MED value.