Twin Transition denotes the dual transformation toward digitalization and sustainability. The concept is promising but lacks empirical evidence whether digital infrastructure really improves environmental conditions or on the contrary. This study adopts the difference-in-difference (DID) model to examine the impact of China’s policy shock of 5G Pilot Program on enterprises’ environmental, social, and governance (ESG) performance. The policy was carried out in batches across 40 scientifically selected cities, forming quasi-natural experiment. Using panel data covering 50,838 A-share listed firms from 2009 to 2024, we find adopting 5G improved the ESG performance of enterprises. Mechanism tests show two mediating paths: accelerated corporate digital transformation and promoted green technological innovation. Heterogeneity analysis showed stronger effect for non-state-owned enterprises, in high-tech industries, and in the eastern region of China. This study provides empirical evidence at firm level for the interaction mechanism between digitalization and sustainability, lending reference for informed strategy formulation and governance.