Some studies have found that women outperform men in episodic memory after midlife. But is this finding universal, and what are the reasons? Gender differences in cognition are the result of biopsychosocial interactions throughout the life course. Social-cognitive theory of gender development posits that gender roles may play an important mediating role in these interactions. We analyzed country differences in the gender differential in cognition after midlife using data from individuals age 50 and above (N = 226,661) from 27 countries. As expected, older women performed relatively better in countries characterized by more equal gender-role attitudes. This result was robust to cohort differences as well as reverse causality. The effect was partially mediated by education and labor-force participation. Cognition in later life thus cannot be fully understood without reference to the opportunity structures that sociocultural environments do (or do not) provide. Global population aging raises the importance of understanding that gender roles affect old-age cognition and productivity.