Background: Brazil has the third largest prison population in the world. Research in the world has confirmed a high prevalence of mental disorders in this population. Objective: To identify prevalence and associated factors with depression and anxiety in prisoners of the closed prison system. Methods: This is a cross-sectional study with 643 prisoners were interviewed in six prisons in Rio Grande do Sul, Brazil. To evaluate depression and anxiety, the Mini International Neuropsychiatric Interview 5.0 (MINI) was used and sociodemographic, inprisonment and lifestyle habits variables were also collected. Results: The prevalence of depression found in the study was 20.6% (95% CI: 17.5-23.8) and of anxiety was 19.9% (95% CI: 16.8-23.0). The following were identified as risk factors for depression: being female, having a history of mental illness, non-white skin color, having a religion, not receiving visits, smoking, using drugs and not performing physical activities. Risk factors for anxiety were: being female, having a history of mental illness, a family history of mental illness, smoking and using drugs. Discussion: The study confirmed the high rates of depression and anxiety in the population deprived of liberty. In addition, women were twice as likely to have both disorders compared to men.