We describe how sexual harassment contributes to sex segregation and pay inequality in the labor market. Combining nationally representative survey data and administrative data, we show that both harassment and wages vary strongly and systematically across workplaces. Women self-report more harassment from colleagues and managers in male-dominated workplaces where wages are relatively high, and men self-report more harassment in female-dominated workplaces where wages are low. These patterns imply two ways that harassment may contribute to gender inequality. First, harassment deters women and men from applying for jobs in workplaces where they are the gender minority. A survey experiment with hypothetical job choices supports this mechanism. Respondents are highly averse to accepting jobs in workplaces with a higher harassment risk for their own gender, but less averse when people of the opposite sex are at higher risk. A second way that harassment contributes to inequality is by making workplace gender minorities leave their workplaces for new jobs. An analysis of workplace transitions supports this mechanism. Women who self-report harassment are more likely to switch to new workplaces with more female colleagues and lower pay.