This study provides a viable path to save energy by means of e-commerce development. Taking the national e-commerce demonstration cities (NEDC) pilots policy implemented in China as a quasi-natural experiment, based on the city panel data from 2006 to 2019, this study applies the multi-period difference-in-difference (DID) method to evaluate the effect of NEDC on energy saving in pilot cities. The empirical results suggest that the NEDC policy obviously contributes to energy conservation. The treated cities reduced energy consumption by 14.2% as a result of the implementation of NEDC, relative to the untreated cities. The conclusions remain valid after conducting robustness tests such as placebo test, instrumental variables regression, propensity score matching-difference-in-difference (PSM-DID), and synthetic difference-in-difference (SDID). The NEDC achieves energy-saving effects through technological innovation, industrial restructuring, and economic agglomeration. Furthermore, the heterogeneity analysis indicates that, in cities with high levels of human capital, well-developed information infrastructure, non-resource-based cities, and favorable business environments, the impact of NEDC on energy saving is more significant. Analysis of spatial effects shows that the implementation of NEDC has negative externalities, increasing energy consumption in the surrounding area. In the context of the digital economy, this paper presents new insights on the relationship between e-commerce and energy consumption and provides policy direction for countries looking for energy-saving solutions.