The sustainability of the ecological environment has been greatly threatened. Based on carbon emissions and combined with the panel data of 30 provinces in China from 2003 to 2020, this paper studied the various mechanisms of industrial structure optimization and population agglomeration on carbon emissions. The fixed effect model, panel threshold model and spatial spillover model are used to study the direct and indirect effects of industrial structure optimization and population agglomeration on carbon emissions, and the robustness of the results is tested in various ways. In terms of direct effects, the industrial structure optimization has a significant negative effect on carbon emissions, and the significance level is 1%. Population agglomeration has a significant positive effect on carbon emissions, with a significance level of 1%. In terms of indirect effects, 1) by adding the cross term of industrial structure optimization and population agglomeration, it is proved that population agglomeration can promote the carbon emission reduction effect of industrial structure optimization. 2) Population agglomeration was used as the threshold variable to verify the interval effect of industrial structure optimization on carbon emission reduction. The results show that the industrial structure optimization has a double threshold effect of population agglomeration on carbon emissions, and the threshold values are 2.1137 and 5.9263, respectively. And the larger the population agglomeration interval, the weaker the inhibition effect of industrial structure optimization on carbon emissions. 3) The industrial structure optimization, population agglomeration and carbon emissions have significant spatial spillover effects. The industrial structure optimization in neighboring areas has a significant inhibitory effect on carbon emissions, and the population agglomeration in neighboring areas has a significant promoting effect on carbon emissions.