OBJECTIVES: Growing evidence suggests that religiosity is an important social determinant of health, including cognitive health. Yet most prior work focused on older adults or was conducted in racially and denominationally homogeneous regional samples. This study investigates the association of religious service attendance in midlife with cognitive function later in midlife. METHODS: Using data from the Coronary Artery Risk Development in Young Adults (CARDIA) study, a racially and geographically diverse prospective cohort study, we explored the association of religious service attendance in midlife with cognitive function 5 years later. Cognitive function was measured using four cognitive tests administered by CARDIA technicians. Multivariable linear regression was used for analyses. Primary analyses controlled for sociodemographics, physical health, depression, and prior religious involvement. Sensitivity analyses additionally controlled for baseline cognition and social support. RESULTS: Our study population included 2,716 participants (57.2% female, 44.9% Black, and mean age 50). In primary analyses, attending services more than weekly (compared to never) in midlife was associated with better global cognition (β = 0.14 standard deviations, 95% [confidence interval] CI = 0.02, 0.26) and verbal memory (β = 0.17 standard deviations, 95% CI = 0.04, 0.30), but not with processing speed (β = 0.04 standard deviations, 95% CI = -0.08, 0.16). A reverse association was observed with executive function (β = -0.16 standard deviations, 95% CI = -0.30, -0.02). Most findings persisted in analyses accounting for loss to follow-up via inverse probability weighting. DISCUSSION: Our findings suggest that frequent involvement in religious services at midlife is associated with better global cognition and verbal memory but worse executive function. There was no association with processing speed.