As the demand for investment products tied to environmental, social and governance (ESG) concerns rises, ESG stock indices have been established. These indices aim to aid investors in navigating and assessing the risks associated with firms based on ESG factors and potential investment returns. The objective of the article is to predict ESG stock indices using a machine learning approach. We use daily data of Dow Jones Sustainability Index (DJSI) World, DJSI Asia Pacific and DJSI Emerging Market from 2018 to 2022 as samples. Two-layer ensemble model – combination of support vector machine (SVM), random forest (RF), long short-term memory (LSTM) and gated recurrent unit (GRU) algorithms – is employed to forecast the indices. The results show that the ensemble model accurately forecasts the indices, with the prediction line closely matching the actual values. It gives the implication that investors are able to improve investment decisions, assist in managing investment risk, and optimize their portfolio diversification. Meanwhile, policymakers are able to anticipate economic trends, inflation and interest rates, assisting in the development of successful economic policies. This research article presents a machine learning approach for predicting ESG stock indices. The proposed model combines SVM, RF, LSTM and GRU algorithms to create a powerful two-layer ensemble model that outperforms individual models. The results show that the ensemble model accurately forecasts ESG stock indices, with the prediction line closely matching the actual values. The model offers insights into the behaviour of different algorithms, highlighting their strengths and limitations. The proposed model can guide decision-making processes, support investment strategies, and ultimately contribute to advancing sustainable investment practices.