At least six major automakers — including Ford, Mercedes-Benz, General Motors and Volvo — and 30 national governments pledged on Wednesday to work toward phasing out sales of new gasoline and diesel-powered vehicles by 2040 worldwide, and by 2035 in “leading markets.”

But some of the world’s biggest car manufacturers, including Toyota, Volkswagen, and the Nissan-Renault alliance did not join the pledge, which is not legally binding. And the governments of the United States, China and Japan, three of the largest car markets, also abstained.

The announcement, made during international climate talks here, was hailed by climate advocates as yet another sign that the days of the internal combustion engine could soon be numbered. Electric vehicles continue to set new global sales records each year and major car companies have recently begun investing tens of billions of dollars to retool their factories and churn out new battery-powered cars and light trucks.

“Having these major players making these commitments, though we need to make sure that they follow through, is really significant,” said Margo Oge, a former senior U.S. air quality official who now advises both environmental groups and auto companies. “It really tells us that these companies, and their boards, accept that the future is electric.”

The automakers that signed the pledge accounted for roughly one-quarter of global sales in 2019.

The 30 countries that joined the coalition included Britain, Canada, India, the Netherlands, Norway, Poland, and Sweden. Earlier counts, based on news releases from conference organizers, had placed the number of national governments at 29 and 31.

The addition of India was especially notable, since it is the world’s fourth-largest auto market and has not previously committed to eliminating emissions from its cars on a specific timeline.

Other countries vowing for the first time to sell only zero-emissions vehicles by a set date included Turkey, Croatia, Ghana and Rwanda.

California, New York State and Washington State also signed the pledge. Last year, Gov. Gavin Newsom of California signed an executive order saying that only new zero-emissions vehicles would be sold in the state by 2035, though regulators have not yet issued rules to make that happen. Gov. Kathy Hochul of New York signed into law a bill that set a similar goal earlier this year. Washington had not previously made such a formal pledge.

The agreement states that automakers will “work toward reaching 100 percent zero-emission new car and van sales in leading markets by 2035 or earlier, supported by a business strategy that is in line with achieving this ambition, as we help build customer demand.”

Zero-emissions vehicles could include either plug-in electric vehicles or hydrogen fuel-cell vehicles, although the latter have struggled to gain market share. Electric cars can still indirectly produce emissions if, for instance, they are recharged with power from plants that burn coal or natural gas. But they are generally considered cleaner overall than combustion engine vehicles and do not create pollution from their tailpipes.

Two dozen vehicle fleet operators, including Uber and LeasePlan, also joined the coalition, vowing to operate only zero-emissions vehicles by 2030, “or earlier where markets allow.”

Worldwide, transportation accounts for roughly one-fifth of humanity’s carbon dioxide emissions that are responsible for climate change, with a little less than half of that coming from passenger vehicles such as cars and vans.

In recent years, spurred by concerns about global warming and air pollution, governments around the world — including China, the United States and the European Union — have begun heavily subsidizing electric vehicles and imposing more stringent emissions standards on new gasoline- and diesel-fueled cars.

The cost of lithium-ion batteries has also declined roughly 80 percent since 2013, according to BloombergNEF, an energy research group, making electric vehicles increasingly competitive with traditional combustion engine vehicles, though many consumers remain wary of the new technology because of concerns like the availability of charging stations.

“We have the technology to make clean road transport a reality and today it’s clear we have the willpower to do it in the next decade,” said Nigel Topping, who was appointed by the British government to the United Nations to be a “high level climate action champion.”

Some of the automakers that signed the agreement had already pledged to clean up the cars they produce. G.M. said in January that it aimed to stop selling new gasoline-powered cars and light trucks by 2035 and will pivot to battery-powered vehicles. Volvo had said it expected its car lineup to be fully electric by 2030.