Investment in energy plays a pivotal role in bridging the financial gap in energy systems, thus balancing the energy trilemma, i.e., energy security, energy equity, and environmental sustainability in developing countries. Despite the capacity of powering the energy systems, there is no existing literature on the impact of public investment in energy, including total, renewable, and non-renewable, on the energy trilemma. Moreover, the literature on the intersection of public investment in energy, institutional factors, economic factors, and the energy trilemma remains sparse. This study, therefore, seeks to investigate the influence of different forms of public investment in energy, including total, renewable, and non-renewable, on the energy trilemma in developing countries. Using the fixed effect with DK standard error and IV-GMM estimator with Driscoll-Kraay standard errors and data from 49 developing countries from 2000 to 2023, our findings outline a positive effect of public investment in energy on the energy trilemma. The study also investigates the role of financial development and economic complexity in moderating the relationship between total public investment in energy and the energy trilemma in developing countries. The results, however, suggest that the better financial system and stronger economic foundations help in channelizing the total public investment in energy, thus balancing the energy trilemma in developing countries. Moreover, the study employs the panel quantile IV regression estimation technique to check the effects of independent variables on the distribution of the energy trilemma in developing countries. The result indicates a positive effect of public investment on energy trilemma at the higher quantiles. These findings offer economic and institutional foundations for channelizing the public investment in energy to balance the energy trilemma and achieve SDG 7 and 13 in developing countries.