Using a random judge design and panel data from Norway, we estimate that imprisonment discourages further criminal behavior, with reoffense probabilities falling by 29 percentage points and criminal charges dropping by 11 over a 5-year period. Ordinary least squares mistakenly reaches the opposite conclusion. The decline is driven by individuals not working prior to incarceration; these individuals increase participation in employment programs and raise their future employment and earnings. Previously employed individuals experience lasting negative employment effects. These findings demonstrate that time spent in prison with a focus on rehabilitation can be preventive for a large segment of the criminal population.