With the recent technological advancements, such as the internet, big data, and cloud computing, China’s digital economy plays a significant role in economic development. However, the digital economy may also affect the environmental quality, but the prevailing literature is scant on how the digital economy affects urban environmental pollution. To fill this gap, this study established an urban digital economy index system based on 277 prefecture-level cities in China and calculated their digital economy indicators from 2011 to 2019. Using a two-way fixed effects model, a mediation effect model and a moderation effect model, a multi-dimensional empirical test is conducted to determine the impact of the digital economy on urban pollution effects and internal mechanisms. Empirical results indicate that the digital economy significantly reduces urban pollutant emissions and shows spatial heterogeneity. After a series of robustness tests and endogenous analysis, our findings are consistent. The mechanism test results reveal that the digital economy can help mitigate pollution emissions through improved industrial structure, promotion of green innovation, and financial development. Further, the empirical results also demonstrate that government intervention can significantly enhance the negative environmental impact of the digital economy. Moreover, the findings from the heterogeneity test (i.e., city size, time, and space heterogeneity) show that the development of the digital economy is more significant in reducing urban pollution in large and eastern coastal cities. While the digital economy development policy impact of the digital economy on reducing pollution has been found after being adjusted by the national strategy. Our study enriches the research regarding the causes and mechanisms of environmental pollution, provides empirical evidence that the digital economy contributes to pollution control and provides decision-making references for enabling the growth of the digital economy and maximizing its pollution reduction power.