Understanding whether, and in what situations, time spent in prison is criminogenic or preventive has proven challenging due to data availability and correlated unobservables. This paper overcomes these challenges in the context of Norway’s criminal justice system, offering new insights into how incarceration affects subsequent crime and employment. We construct a panel dataset containing the criminal behavior and labor market outcomes of the entire population, and exploit the random assignment of criminal cases to judges who differ systematically in their stringency in sentencing defendants to prison. Using judge stringency as an instrumental variable, we find that imprisonment discourages further criminal behavior, and that the reduction extends beyond incapacitation. Incarceration decreases the probability an individual will reoffend within 5 years by 29 percentage points, and reduces the number of offenses over this same period by 11 criminal charges. In comparison, OLS shows positive associations between incarceration and subsequent criminal behavior. This sharp contrast suggests the high rates of recidivism among ex-convicts is due to selection, and not a consequence of the experience of being in prison. Exploring factors that may explain the preventive effect of incarceration, we find the decline in crime is driven by individuals who were not working prior to incarceration. Among these individuals, imprisonment increases participation in programs directed at improving employability and reducing recidivism, and ultimately, raises employment and earnings while discouraging further criminal behavior. For previously employed individuals, while there is no effect on recidivism, there is a lasting negative effect on employment. Contrary to the widely embraced ‘nothing works’ doctrine, these findings demonstrate that time spent in prison with a focus on rehabilitation can indeed be preventive for a large segment of the criminal population.