We used data from the Scottish Veterans Health Study to examine long-term mental health outcomes in a large cohort of veterans, with a focus on the impact of length of service. We conducted a retrospective, 30-year cohort study of 56,205 veterans born from 1945 through 1985, including 14,702 who left military service prematurely, and 172,741 people with no record of military service, using Cox proportional hazard models, to examine the association between veteran status and length of service and cumulative risk of mental health disorder. We stratified the veterans by common lengths of service, defining Early Service Leavers as those who had served for less than 2.5 years. There were 2,794 (4.97%) first episodes of any mental health disorder in veterans, compared with 7,779 (4.50%) in nonveterans. The difference was statistically significant for all veterans (adjusted hazard ratio [HR] = 1.21; 95% CI, 1.16-1.27; P < .001). Subgroup analysis showed the highest risk to be in Early Service Leavers (adjusted HR = 1.51; 95% CI, 1.30-1.50; P < .001), including those who failed to complete initial training. The risk reduced with longer service; beyond 9 years of service, risk of mental health disorder was comparable to or lower than that in nonveterans. The veterans at highest risk of mental health disorder were those who did not complete training or minimum engagement, while those with longest service were at reduced risk, suggesting that military service was not causative. The high risk among the earliest leavers may reflect pre-service vulnerabilities not detected at recruitment, which become apparent during early training and lead to early discharge.