Natural gas import security has been a hot issue, and its environmental effects remain unsettled. In the context of carbon neutrality, this study aims to investigate the nexus between natural gas import security and CO2 emissions. For this purpose, we propose an effective composite index to measure the natural gas import security levels of 30 countries over the period 2004–2019. Then we construct a dynamic panel data model to estimate the impact of natural gas import security on CO2 emissions. To ensure effective and robust estimations, the SYS-GMM and D-GMM methods are simultaneously employed. We further conduct a mediating effect and heterogeneity analysis on the nexus between natural gas import security and CO2 emissions. The estimation results indicate that an increase in natural gas import security can indeed reduce global CO2 emissions. Furthermore, natural gas import security can reduce CO2 emissions by adjusting the energy consumption structure. Moreover, the mitigation effect of natural gas import security on CO2 is dominated by the substitution effect of natural gas for other fossil fuels. In addition, heterogeneity exists in the nexus between natural gas import security and CO2. The findings provide new insights for reducing carbon emissions and improving gas security.