While neoclassical theory emphasizes the impact of trade on wage inequality between occupations and industries, more recent theories of firm heterogeneity point to the impact of trade on wage dispersion within occupations and industries. Using linked employer-employee data for Brazil, we show that much of the increase in wage inequality between 1986 and 1998 has occurred within sector-occupations; the increase in the within component of wage inequality is driven by wage dispersion across firms; and the change in wage dispersion between firms is related to trade participation. We then use an extension of the theoretical model from Helpman, Itskhoki, and Redding (2010a) to construct an econometric model of the effect of trade on inequality, which we estimate with Brazilian data. We show that the estimated model fits the data well, both in terms of some key moments as well as in terms of the overall distributions of wages and employment. International trade is important for this fit. In particular, we show that by shutting down the trade channel the estimated model is significantly less successful in matching the data. Finally, we quantify the contribution of the firm-based channel through which trade affects wage inequality.