The rapid development of the digital economy profoundly impacts global industries, presenting both opportunities and challenges for traditional sectors like petroleum. This study investigates the impact of the digital economy on the performance of Chinese petroleum enterprises, focusing on the mediating role of total factor productivity (TFP). Utilizing panel data from Chinese petroleum firms (2018–2023), we construct a macro digital economy development index (using the entropy method) and a micro-level enterprise digital transformation index. Empirical analysis employs panel data models and mediation effect models. Findings reveal that regional digital economy development significantly positively affects firms’ Tobin’s Q (coefficient = 0.516). Enterprise digital transformation significantly enhances Return on Equity (ROE) (coefficient = 27.456). Mediation tests confirm that TFP partially mediates the relationship between digital transformation and firm performance. Heterogeneity analysis shows differences based on ownership: regional digital economy development has a slightly stronger effect on state-owned enterprises’ (SOEs) market value, while its effect is statistically more significant for private enterprises. Conversely, digital transformation boosts ROE more significantly in private firms. The study concludes with policy recommendations, including promoting digital governance reform in SOEs, increasing support for private firms’ digitalization, building a digital technology innovation ecosystem to enhance TFP, and optimizing digital investment structures for better capital market recognition.