This paper analyses the impact of trade liberalization in a model where heterogeneous firms can freely offshore their production. Firms choose whether to produce, and if so whether to sell on the domestic market only or on the export market as well. Simultaneously, they also choose where to locate their production. The paper shows that the interaction between heterogeneity in firm productivity and the possibility of offshoring production dramatically alters the impact of trade liberalization. Three main results emerge from this interaction: i) Intra-industry factor reallocation towards the most productive firms, which is induced by trade liberalization, operates at the world level, but not necessarily at the country level and thus trade liberalization can lead to average productivity losses in some countries; ii) Trade liberalization may reverse country specialization independently of any country size effect; iii) The relation between trade liberalization and trade growth is non-linear, even in the absence of trade in intermediate goods.