We study the gains from trade in an economy with oligopolistic competition, firm heterogeneity, and innovation. Oligopolistic competition together with free entry make markups responsive to firm productivity and trade costs. Lowering trade costs reduces markups on domestic sales but increases markups on export sales, as firms do not pass the entire reduction in trade costs onto foreign consumers. Nevertheless, the downward pressure dominates and the average markup declines, deterring firms from entering the market and leading to higher market concentration. Neither the increased concentration nor the incomplete pass-through of trade costs to export markups are strong enough to compensate for the increase in competition on domestic sales. Thus the overall effect of trade on markups is pro-competitive and a key source of the associated welfare gains. In addition to markups, selection and innovation provide additional channels through which the trade-induced effect on competition impacts welfare. In a quantitative exercise, we decompose the total gains from trade into these three contributing channels; we find that innovation plays a small but non-negligible role, while the main component is equally split between the pro-competitive and the selection channel.