Parental leave policies have been hypothesized to benefit mothers' mental health. We assessed the impact of a 6-week extension of parental leave in Denmark on maternal mental health. We linked individual-level data from Danish national registries on maternal sociodemographic characteristics and psychiatric diagnoses. A regression discontinuity design was applied to study the increase in parental leave duration after 26 March 1984. We included women who had given birth between 1 January 1981 and 31 December 1987. Our outcome was a first psychiatric diagnosis following the child's birth, ascertained as the first day of inpatient hospital admission for any psychiatric disorder. We presented cumulative incidences for the 30-year follow-up period and reported absolute risk differences between women eligible for the reform vs not, in 5-year intervals. In all, 291 152 women were followed up until 2017, death, emigration or date of first psychiatric diagnosis. The median follow-up time was 29.99 years, corresponding to 10 277 547 person-years at risk. The cumulative incidence of psychiatric diagnoses at 30 years of follow-up was 59.5 (95% CI: 57.4 to 61.6) per 1000 women in the ineligible group and 57.5 (95% CI: 55.6 to 59.4) in the eligible group. Eligible women took on average 32.85 additional days of parental leave (95% CI: 29.20 to 36.49) and had a lower probability of having a psychiatric diagnosis within 5 years [risk difference (RD): 2.4 fewer diagnoses per 1000 women, 95% CI: 1.5 to 3.2] and up to 20 years after the birth (RD: 2.3, 95% CI: 0.4 to 4.2). In subgroup analyses, the risk reduction was concentrated among low-educated, low-income and single women. Longer parental leave may confer mental health benefits to women, in particular to those from disadvantaged backgrounds.