PurposeThis article aims to analyse the relationship between the environmental, social and governance (ESG) score and the cost of capital of 600 large, mid and small capitalization companies across 17 countries that are component of the EURO STOXX 600 Index. By examining whether ESG has an impact on the cost of capital, this article contributes to the solutions to improve the impact of organizations and societies on sustainable development. The article further examines whether the effect is because of the environmental, social and/or governance components. In addition, the article analyses which WACC component (i.e. the cost of equity, the cost of debt, the beta or the leverage ratio) is affected. Furthermore, this article analyses whether a high ESG score can substitute for a weaker legal environment.Design/methodology/approachThe results were obtained by using ordinary least squares panel data modelling to analyse the relationship between the ESG score and the cost of capital. The sample consists of companies that are part of the STOXX Europe 600 Index over the period 2018–2021, which is composed of 600 companies, including large, mid and small capitalization firms listed across 17 countries. The sample finally includes 1,960 firm-year observations.FindingsCompanies with a higher ESG score tend to have a lower cost of capital, but this relationship holds only for firms domiciled in countries with a weaker legal environment. In addition, these firms should not only increase their ESG score to create a more sustainable environment but also to reduce their cost of debt. Environmental and social factors have a significantly negative impact on the cost of capital only in countries with a weaker legal environment, while the governance component positively impacts the cost of capital by allowing firms to borrow more.Research limitations/implicationsThere is not yet a standardized taxonomy to define ESG, making the study dependent on commercial data providers.Practical implicationsThe new insights can be used by companies domiciled in countries with weaker legal environments to reduce their cost of capital. The results also allow us to know on which components of the ESG score to focus. It can also help policymakers, specifically those in countries with a weaker legal environment, to provide incentives to further stimulate ESG investments and disclosure, thereby contributing to a more sustainable society.Social implicationsTo achieve the sustainable development goals put forward by the United Nations, it is important for firms to invest in ESG projects. It is nevertheless insightful to know whether these ESG investments, which are currently observed as a cost, also provide benefits to firms and in which countries. If firms clearly see the advantages of investing in ESG projects, they are likely to proactively engage in them.Originality/valueThis article is the first, to the best of the authors’ knowledge, to focus on 17 European countries, thereby capturing divergent legal environments. This setting allows us to answer the main novel research question, namely, whether the ESG score can act as a substitute for the legal environment in which the company is domiciled. The article also goes further than previous articles by examining whether the effect is because of the environmental, social and/or governance component and whether these impact the components of the weighted cost of capital, namely, the cost of equity, the cost of debt, the beta or the leverage ratio of the companies.