Recently, there has been interest in the relationship between mental health and air pollution; however, the results are inconsistent and the contribution of foreign direct investment (FDI) has received little attention. This article studies the effects of air pollution on mental health and the moderating role of FDI based on the China Health and Retirement Longitudinal Study (CHARLS) data in 2015 and 2018 applying the fixed effects panel regression approach and the threshold model. The results show that mental health is adversely affected by air pollution, especially PM2.5, PM10, sulfur dioxide (SO2), carbon monoxide (CO), and nitrogen dioxide (NO2). Second, FDI has an alleviating influence on the negative relationship. Third, the effects of air pollution and FDI are heterogeneous based on regional characteristics, including location, medical resource and investment in science and technology, and individual characteristics covering education level, age, income, and physical health. Finally, the threshold effects show that FDI has a moderating effect when it is >1,745.59 million renminbi (RMB). There are only 11.19% of cities exceeding the threshold value in China. When the value of air quality index (AQI) exceeds 92.79, air pollution is more harmful to mental health. Government should actively introduce high-quality FDI at the effective level and control air pollution to improve mental health.