We develop an equilibrium wage-posting model with heterogeneous firms that decide to locate in the formal or the informal sector and workers who search randomly on and off the job. We estimate the model on Brazilian labor force survey data. In equilibrium, firms of equal productivity locate in different sectors, a fact observed in the data. Wages are characterized by compensating differentials. We show that tightening enforcement does not increase unemployment and increases wages, total output, and welfare by enabling better allocation of workers to higher productivity jobs and improving competition in the formal labor market.