The topics of companies' Environmental, Social, and Governance (ESG) performance and two-way Foreign Direct Investment (FDI) behavior are gaining prominence in China. Analyzing the relationship between ESG performance and two-way FDI behavior can guide companies towards adopting green and open practices. This study covers the period from 2009 to 2022, focusing on 2022 listed companies using unbalanced panel data with 13,365 observations. The results establish that a company's ESG performance significantly contributes to its twoway FDI behavior. Endogeneity analysis and robustness checks are consistent with the baseline regression findings. Non-state owned enterprises, large companies, and non-high-tech companies particularly benefit from ESG performance in their two-way FDI behavior. The COVID-19 pandemic likely amplified the significance of ESG factors in the decision-making process for two-way FDI behavior. Mechanism analysis indicates that ESG performance promotes innovation and efficiency, enhancing companies' ownership advantage. Additionally, ESG performance could enhance companies' reputation and bring information symmetry advantages. The study presents evidence that ESG performance acts as a substitute for digital transformation in driving companies' twoway FDI behavior. These three mechanisms contribute to a greater likelihood of two-way FDI behavior. These findings are of significant importance to both businesses and policymakers, guiding companies toward adopting more environmentally friendly and open practices, thereby promoting sustainable development and fostering growth in two-way FDI.