Enterprise digital transformation involves leveraging digital technologies to optimize and improve business operations. Not only does it augment operational efficiency, but it also establishes favorable conditions for bolstering ESG. To investigate the impact of digital transformation on ESG performance, this study employs a fixed effects model. The analysis utilizes data from a sample of 1422 publicly listed companies in China, spanning the period of 2012 to 2021. This paper further explores the mechanism and heterogeneity behind this impact. The research findings indicate that digital transformation has a positive impact on the ESG performance of companies. It remains robust even after conducting robustness tests, which include omitted variable and endogeneity tests. Furthermore, the study identifies variations in the influence of digital transformation on different dimensions of ESG performance. Through a mechanism analysis, it is revealed that digital transformation positively affects ESG performance by optimizing the structure of human capital, enhancing operational efficiency, and promoting green innovation. Additionally, heterogeneity analysis indicates that the positive effect of digital transformation on ESG performance is particularly significant in capital-intensive industries, high-tech companies, and companies with low carbon emissions.