A new global climate deal has been struck after being brought back from the brink of disaster by three powerful women politicians in a 20-minute "huddle to save the planet".
A major crisis had been provoked after 3am on Sunday morning when the EU clashed furiously with China and India over the legal form of a potential new treaty. The EU plan to bind all countries to cuts was close to collapse after India inserted the words "legal outcome" at the last minute into the negotiating text.
EU climate commissioner Connie Hedegaard, backed by UK energy secretary Chris Huhne, said it would have made the EU plan legally meaningless and would have forced the EU to walk away, effectively collapsing the negotiations.
With ministers exhausted after nearly six days and three nights of intense discussions, Hedegaard told the 194 countries in Durban: "We need clarity. We need to commit. The EU has shown patience for many years. We are almost ready to be alone in a second commitment period [to the Kyoto protocol].
"We don't ask too much of the world that after this second period all countries will be legally bound. Let's try and have a protocol by 2018."
The Indian environment minister, Jayanthi Natarajan, responded fiercely that developing countries were being asked to sign up to the deal before they knew what was in the proposed treaty, and whether it would be fair to poor nations.
"Am I to write a blank cheque and sign away the livelihoods and sustainability of 1.2 billion Indians, without even knowing what the EU roadmap contains?
"I wonder if this is an agenda to shift the blame on to countries who are not responsible. I am told that India will be blamed. Please don't hold us hostage. We will give up the principle of equity."
China's chief negotiator, Xie Zhenhua, lambasted the EU in a passionate speech, saying: "Who gives you the right to tell us what to do?"
With tempers rising and the talks minutes from being abandoned, the chair, South African foreign minister Maite Nkoana-Mashabane, ordered China, India, the US, Britain, France, Sweden, Gambia, Brazil and Poland to meet in a small group or "huddle".
Surrounded by a crowd of nearly 100 delegates on the floor of the hall, they talked quietly among themselves to try to reach a new form of words acceptable to all.
But it was Brazil's chief negotiator, lawyer Luiz Alberto Figueiredo, who came up with the compromise, proposing to substitute "an agreed outcome with legal force" for "legal outcome". This, said an EU lawyer, was much stronger, effectively meaning "a legally binding agreement".
"Yes, yes," cheered the crowd of onlookers around the politicians, and the talks were back on track.
Two hours later the 16-day talks were effectively over, with a commitment by all countries to accept binding emission cuts by 2020. As part of the package of measures agreed, a new climate fund will be set up, carbon markets will be expanded and countries will be able to earn money by protecting forests.
Chris Huhne hailed the conclusion of the talks as "a triumph of European co-operation".
"We have taken a significant step forward. This will give business confidence and stop us locking in a whole generation of high-carbon technology," he said.
But Martin Khor, director of the intergovernmental South Centre in Geneva, said poor countries would be obliged to cut emissions proportionally more than the rich. "It's like the starving will be made to give up half their small amount of food but the rich just a bit," he said.
Green groups said the ambition shown by countries to reduce emissions was paltry. "Negotiators have sent a clear message to the world's hungry: let them eat carbon," said Celine Charveriat, director of campaigns and advocacy for Oxfam.
"Governments must immediately turn their attention to raising the ambition of their emissions cuts targets and filling the Green Climate Fund. Unless countries ratchet up their emissions cuts urgently we could still be in store for a 10-year timeout on the action we need to stay under two degrees [of temperature increase]."
Greenpeace International director Kumi Naidoo said: "The chance of averting catastrophic climate change is slipping through our hands with every passing year that nations fail to agree on a rescue plan for the planet."
"This will force governments to admit their current pledges to cut emissions are not enough to achieve 2C rise and will have to be strengthened," said Michael Jacobs, of the Grantham climate research institute of climate change.
Nnimmo Bassey, chair of Friends of the Earth International, said: "Delaying real action till 2020 is a crime of global proportions.
"This means the world is on track to a 4C temperature rise, a death sentence for Africa, small island states and the poor and vulnerable worldwide. The richest 1% of the world have decided that it is acceptable to sacrifice the 99%."