The 50-59 age group in the U.S. experience higher levels of food insecurity (FI) compared to older adults. While previous research has identified an association between FI and cognition outcomes in older populations, limited research has examined midlife as a specific food insecurity exposure window and the association of this hardship with long-run cognition outcomes. Utilizing 14 waves of Health and Retirement Survey (HRS) data (1995-2020), I applied mixed-effects models to assess the relationship between midlife FI exposure and later-life cognitive function, controlling for childhood disadvantages and other health-related and sociodemographic characteristics. Findings indicate that both cumulative FI duration and ever experiencing FI during ages 50-59 are significantly associated with subsequent cognitive decline. Specifically, ever experiencing food insecurity during midlife was linked to a decrease in cognitive function by 0.07 standard units (95% CI, -0.13 to -0.003; P<0.05). In addition, each additional year of FI exposure during midlife was associated with a reduction in cognitive function by 0.01 standard units (95% CI, -0.03 to -0.003; P<0.05). These associations remained robust even after accounting for a range of potential confounders and covariates. The findings support the cumulative inequality model, suggesting that midlife food insecurity is a significant predictor of lower cognitive function in later life. Both the timing and extent of FI during midlife are crucial factors in shaping cognitive health outcomes. Policy interventions targeting food insecurity in the 50-59 age group could play a pivotal role in promoting healthy aging and mitigating cognitive decline in older adulthood.