We analyze a two-country model of Foreign Direct Investment (FDI). Two firms, each of which is originally situated in only one of the two countries, first decide whether to build a plant in the foreign country. Then, they decide whether to relocate R&D activities. Finally, they engage in product-market competition. Our main points are: first, FDI liberalization causes a relocation of R&D activities if intrafirm communication is sufficiently well developed, external spillovers are substantial, competition is not too strong and foreign markets are not too small. Second, such a relocation of R&D activities will usually nevertheless increase domestic welfare since it only occurs if intrafirm communication is well developed and therefore knowledge generated and obtained abroad flows back to the domestic country. Third, the potential of R&D offshoring makes FDI itself more likely. Fourth, when countries are asymmetric, the small-country firm is more likely to offshore its R&D activities into the large country than conversely.