Digital finance enhances corporate ESG performance and is essential for achieving sustainable development; however, its consistent effectiveness in improving ESG outcomes remains contested. Using panel data from A-share listed companies on the Shanghai and Shenzhen stock exchanges in China from 2011 to 2021, this study empirically examines nonlinear effects, transmission mechanisms, and moderating factors. The results indicate a U-shaped relationship between digital finance and ESG performance, with a positive impact becoming apparent when digital finance exceeds the threshold of 3.81. Mechanism tests reveal that green technological innovation and public environmental attention are crucial transmission channels for the nonlinear effects. Furthermore, financial regulation levels and environmental uncertainty negatively moderate this relationship, while corporate digital transformation has a positive moderating effect. Further analysis shows that the U-shaped relationship is more pronounced in areas with lesser financial advancement and higher levels of environmental regulation, as well as in non-high-tech industries, non-manufacturing sectors, smaller firms, and companies without political connections. This study provides empirical evidence and policy insights to support the promotion of financial services that better facilitate corporate sustainability.