Low cognitive ability in late adolescence has previously been shown to be associated with disability pension (DP) in young adulthood. However, most DP's are granted later in working life, and the mechanisms of the association are not fully understood. We aimed to investigate the association between cognitive ability in late adolescence and DP at ages 40-59, and investigate the role of individual and socioeconomic factors. Information on cognitive ability, health status, personality aspects and health behaviours at age 18-20 was obtained from the 1969-70 conscription cohort, comprising 49,321 Swedish men. Data on DP's 1991-2008 was obtained from the Longitudinal Database of Education, Income and Employment. Information on socioeconomic and work-related factors in childhood and adulthood was obtained from national sociodemographic databases. Hazard ratios for DP during follow-up were estimated by Cox proportional hazards models. We found a graded relationship between cognitive ability in late adolescence and DP in middle age. One step decrease on the nine-point stanine scale of cognitive ability was associated with a crude hazard ratio of 1.26 (95% CI 1.24-1.27). Socioeconomic and work-related circumstances in adulthood explained much of the association, but factors measured already in late adolescence also showed importance. The findings suggest an accumulation of risks over the life course. Although attenuated, the graded relationship remained after adjusting for all factors.