DUBAI—More than 190 governments at the United Nations climate conference approved an agreement Wednesday calling for the world to transition away from fossil fuels, sending an unprecedented signal to the global economy that governments are intent on cutting back on coal, oil and natural gas in the fight against global warming.

The deal, the result of all-night talks, calls for “transitioning away from fossil fuels in energy systems, in a just, orderly and equitable manner.” It says the shift to clean energy for the global economy should accelerate this decade with the aim of net-zero greenhouse gas emissions by 2050. Scientists say that is crucial to fulfilling the Paris accord, the landmark climate agreement that calls for governments to attempt to limit global warming to 1.5 degrees Celsius above preindustrial temperatures.

“We should be proud of our historic achievement,” said Sultan Al Jaber, the chief executive of the United Arab Emirates’ national oil company who is running COP28, in a closing address that garnered a standing ovation from many delegates. “We have delivered a robust action plan to keep 1.5 within reach.”

The deal marks the first time a U.N. climate agreement has called for governments to cut back on all fossil fuels. Scientists have long said it, but big fossil-fuel producers led by Saudi Arabia and fast-growing developing nations such as China and India have historically rebuffed pressure to end the use of fossil fuel.

The document “announced the global and irreversible trend toward a green, low-carbon transition,” said Zhao Yingming, vice minister of Ecology and Environment of China. The final wording was acceptable to China, a person familiar with Beijing’s thinking said, because the proportion of fossil fuels in the country’s energy mix has been declining.

The agreement targeting fossil fuels shows a new determination by governments around the world to cut fossil-fuel consumption. Supporters say the agreement should accelerate the flow of private investment into clean energies, such as solar and wind, and away from fossil fuel production. It must still be enshrined in national policies and then implemented, a politically fraught process that is expected to run through 2050 and beyond.

Still, the agreement provides some latitude to oil and gas producers. It doesn’t set a strict timeline for transitioning and endorses so-called carbon capture and storage technology, in which fossil fuels are still burned but the carbon-dioxide emissions are captured and stored. Big oil producers say carbon capture could allow the global economy to keep burning significant quantities of fossil fuels, even as net greenhouse emissions fall to zero.

Albara Tawfiq, Saudi Arabia’s negotiator who represents a coalition of Arab countries, said he appreciated the agreement’s nod to countries having the right to take different approaches to emissions reduction based on their levels of development.

Some environmental groups expressed concern that the deal left loopholes open for the fossil fuel industry.

“The outcome suggests there is a considerable role for dangerous distractions such as large-scale carbon capture and storage and transitional fuels,” said Manuel Pulgar-Vidal, global climate and energy lead for the World Wildlife Fund.

Talks between the U.S. and China—the world’s two biggest emitters—helped create the conditions for an agreement. The two powers stationed their delegations in Dubai in adjacent offices, with U.S. climate envoy John Kerry regularly dropping in on his Chinese counterpart. The two chatted near the podium of Monday’s plenary in front of the entire conference.

Moments later Kerry praised the deal for urging the transition away from fossil fuels “for the first time.”

Governments have been gathering for climate talks since the U.N.’s first global warming agreement was signed in 1992. Until a few years ago, annual agreements hadn’t even mentioned the words “fossil fuel” because of opposition from China, India, Saudi Arabia and, at times, the U.S. The conclusions from the COP26 in Glasgow two years ago called for a phaseout of inefficient fossil-fuel subsidies.

This year, a string of climate-related natural disasters spurred countries to go further. Huge wildfires in Canada during the spring, fueled by unusually warm and dry weather, sent smoke billowing across swaths of the U.S. The U.N. last month said 2023 is the warmest year ever measured, a record that scientists say is partly due to climate change.

In the run-up to this year’s conference, the U.S., Europe and nations on the front lines of climate change began pushing for a sweeping phaseout of all fossil fuels. Saudi Arabia and other oil-producing nations initially shot down those proposals. The Organization of the Petroleum Exporting Countries sent a letter to its members last week, rallying them to oppose “undue and disproportionate pressure against fossil fuels may reach a tipping point with irreversible consequences” and “put our people’s prosperity and future at risk.”

The campaign to target fossil fuels found an unlikely ally in Jaber, who leads one of the world’s largest oil companies. During the conference, he said the “phaseout of fossil fuels is inevitable. In fact, it is essential.” He then pushed countries to find agreement on fossil fuel language when the talks began to teeter.

After consulting with delegates in round-the-clock negotiations, Jaber countered with a compromise that called for a transition to cleaner energy but no phaseout. It also said global renewable energy capacity should triple by 2030, along with the doubling of the rate of energy efficiency improvements.

In a move that riled some countries, the agreement was gaveled before delegates were allowed to deliver remarks on the agreement. Shortly after the deal was adopted, small island nations said they hadn’t been in the conference hall and objected to a number of provisions.

Some environmentalists immediately praised the new language on fossil fuels. The “text sends a strong signal that world leaders recognize that a sharp turn away from fossil fuels toward clean energy in this critical decade and beyond, aligned with the science, is essential to meet our climate goals,” said Rachel Cleetus, an economist at the Union of Concerned Scientists.

Write to Matthew Dalton at Matthew.Dalton@wsj.com, Stacy Meichtry at Stacy.Meichtry@wsj.com and Sha Hua at sha.hua@wsj.com