Evidence suggests that contemporaneous labor force participation affects cognitive function; however, it is unclear whether it is employment itself or endogenous factors related to individuals’ likelihood of employment that protects against cognitive decline. We exploit innovations in counterfactual causal inference to disentangle the effect of postponing retirement on later-life cognitive function from the effects of other life-course factors. With the U.S. Health and Retirement Study (1996–2014, n = 20,469), we use the parametric g-formula to estimate the effect of postponing retirement to age 67. We also study whether the benefit of postponing retirement is affected by gender, education, and/or occupation, and whether retirement affects cognitive function through depressive symptoms or comorbidities. We find that postponing retirement is protective against cognitive decline, accounting for other life-course factors (population: 0.34, 95% confidence interval (CI): 0.20,0.47; individual: 0.43, 95% CI: 0.26,0.60). The extent of the protective effect depends on subgroup, with the highest educated experiencing the greatest mitigation of cognitive decline (individual: 50%, 95% CI: 32%,71%). By using innovative models that better reflect the empirical reality of interconnected life-course processes, this work makes progress in understanding how retirement affects cognitive function.