We show that heterogeneous firms choose different locations in response to market integration. Specifically, decreasing trade costs lead to the gradual agglomeration of efficient firms in the larger country where they have access to a bigger pool of consumers. In contrast, high-cost firms seek protection against competition from efficient firms by locating in the smaller country. However, when the spatial separation of markets ceases to be a sufficient protection against foreign competition, high-cost firms choose to set up in the larger market. Hence, the relationship between economic integration and international productivity gap first increases and then decreases with market integration.