Urban residence is associated with a higher risk of some psychiatric disorders, but the underlying drivers remain unknown. There is increasing evidence that the level of exposure to natural environments impacts mental health, but few large-scale epidemiological studies have assessed the general existence and importance of such associations. Here, we investigate the prospective association between green space and mental health in the Danish population. Green space presence was assessed at the individual level using high-resolution satellite data to calculate the normalized difference vegetation index within a 210 × 210 m square around each person’s place of residence (∼1 million people) from birth to the age of 10. We show that high levels of green space presence during childhood are associated with lower risk of a wide spectrum of psychiatric disorders later in life. Risk for subsequent mental illness for those who lived with the lowest level of green space during childhood was up to 55% higher across various disorders compared with those who lived with the highest level of green space. The association remained even after adjusting for urbanization, socioeconomic factors, parental history of mental illness, and parental age. Stronger association of cumulative green space presence during childhood compared with single-year green space presence suggests that presence throughout childhood is important. Our results show that green space during childhood is associated with better mental health, supporting efforts to better integrate natural environments into urban planning and childhood life.