The directional distance function (DDF) framework has been widely used to estimate the marginal abatement cost (MAC) of CO2 emissions to support decision-making in environmental sustainability and climate change issues. In the use of DDF, an important task is mapping evaluated entities towards a realistic production technology frontier. This study develops a new nonparametric approach for estimating the MAC of CO2 emissions. The approach incorporates the optimal endogenous direction into an enhanced environmental production technology and has three advantages. First, it avoids the arbitrariness in mapping directions. Second, it captures the heterogeneity in optimization paths across different decision-making units (DMUs). Third, it generates more reliable benchmarks for estimating MAC by constructing an environmental technology frontier that is consistent with the material balance principle. We apply the approach to study China's thermal power industry and find clear heterogeneity in MACs and optimization paths at the province level. The results on the optimal endogenous directions show that the DMUs prefer to increase both desirable output and CO2 emissions when CO2 emissions are unregulated. Comparisons with other approaches reveal that arbitrarily mapping exogenous directions and technology representations are likely to generate distorted and unrealistic MACs.