Utilizing the digital economy’s contribution to green total factor productivity is a key strategy for accelerating China’s green growth, although more research is still needed to understand the mechanism of this influence. This study uses panel data from 282 Chinese prefecture-level cities from 2011 to 2019 to empirically assess the impact of the digital economy and city size on GTFP. First, GTFP overall exhibits an upward trend with excellent spatial correlation and minimal regional variation. Second, the findings demonstrate that, while surrounding locations’ GTFP is not affected by the digital economy, local productivity can be improved. Third, the heterogeneity study demonstrates that the digital economy contributes more to local GTFP in the eastern region compared to the central and western regions, with the central region making the largest contribution to GTFP in the surrounding regions; the first, second, and third tier cities have more contributions from the digital economy to local and neighboring GTFP than the fourth and fifth tier cities. Fourth, city size positively modifies the relationship between the green total factor productivity and the digital economy. The western region is where the positive moderating effect of city size expansion is greatest. Moreover, compared to first-, second-, and third-tier cities, the fourth- and fifth-tier cities have a stronger beneficial moderating effect of city size increase. In light of this, we should focus on the growth of the digital economy, optimize city scale, and fully exploit the scale effect produced by the concentration of the digital industries and the spillover effect produced by the spread of the digital technology.