The comprehensive cohesion of the digital economy, structural deviation adjustment, and green development is a crucial step towards promoting high-quality economic growth and realizing carbon peak and carbon neutrality. This paper probes the impact of intra- and inter-regional digital economy on carbon emissions, considering the mediating effect of structural deviation, utilizing panel data from 267 prefecture-level cities in China spanning the years 2011–2019. The findings reveal the following key insights. First, the connection between the digital economy and carbon emissions within cities follows an inverted “U" shape. In the early stages, the digital economy leads to an average increase in carbon emissions of 0.069%. However, in the later stages, the digitized economy markedly decrease emissions. Second, both the digital economy and carbon emissions exhibit spatial spillover effects. Within the region, DE has a significant nonlinear spillover effect on CO2 emissions in the neighboring regions, with the spatial decay boundary of this effect extending up to 380 km. Third, analysis of the impact mechanism reveals that the digital economy mitigates local and neighboring carbon dioxide emissions by adjusting structural deviation. Heterogeneity analysis indicates that the digital economy is more likely to have a carbon emission reduction effect in cities that are not involved in the industrial transfer and those that do not belong to the old industrial base. These findings provide a rationale and policy reference for China to harness the opportunities presented by digital economy development and to achieve the “dual-carbon” goal.