It is unclear whether psychological resilience to stress in adolescence represents a persistent characteristic relevant to the subsequent risk for depression and anxiety in later adulthood. We aimed to test whether low psychological stress resilience assessed in adolescence is associated with an increased risk of receiving medication for depression and anxiety in middle age. We utilized Swedish register-based cohort study. Men born between 1952 and 1956 (n = 175,699), who underwent compulsory assessment for military conscription in late adolescence were followed to examine subsequent risk of pharmaceutically-treated depression and anxiety in middle age, from 2006 to 2009 corresponding to ages between 50 and 58 years, using Cox regression. The associations of stress resilience with prescription of antidepressant and anxiolytics medication through potential mediating factors cognitive and physical function and adult socioeconomic factors were calculated. Low stress resilience was associated with elevated risks for antidepressant (hazard ratio (HR):1.5 (95% CI 1.4 1.6)) and anxiolytics (HR:2.4 (CI 2.0 2.7)) medication. Adjustment for measures of childhood living circumstances attenuated the associations somewhat. Around a third of association with low stress resilience, and a half of that with moderate resilience, was mediated through cognitive and physical function in adolescence and adult socioeconomic factors. The magnitude of the inverse association of higher cognitive function with antidepressant medication was eliminated among those with low stress resilience. These results indicate that low stress resilience in adolescence is associated with an increased risk for antidepressant and anxiolytics medication over 30 years later, in part mediated through developmental factors in adolescence and socioeconomic circumstances in adulthood, and low stress resilience can diminish or eliminate the inverse association of higher cognitive function with antidepressant medication.