The digital economy plays an important role in reducing the global warming process. This paper explores the spatiotemporal heterogeneity impacts of the digital economy on provincial carbon emissions and its underlying mechanisms. Initially, this paper examines the inhibitory impact of the digital economy on carbon emissions, alongside the mediating role of economic agglomeration, at a theoretical level. Subsequently, it empirically explores the quantitative associations among the digital economy, economic agglomeration, and carbon emissions by utilizing Chinese provincial panel data spanning from 2000 to 2021. This investigation employed static and dynamic spatial Durbin models as well as mediation models to analyze the interrelationships. The results firstly revealed that the digital economy notably diminishes carbon emissions, with economic agglomeration playing a significant mediating role. This conclusion remained consistent even after substituting the explanatory variables and weight matrix, modifying the sample period, and conducting other robustness tests. Secondly, the impact of the digital economy on carbon emissions exhibited spatial spillovers. Compared with the impact on the local area, the impact on neighboring provinces was found to be weaker. Thirdly, carbon emissions showed a significant “snowball” effect in the time dimension. This paper emphasizes the important role of digital technology in curbing carbon emissions, and it provides some policy insights for studying the digital economy, economic agglomeration, and carbon emissions. Furthermore, it offers valuable insight and suggestions to reduce carbon emissions and realize the goal of the “dual-carbon” strategy.