UN climate talks in Poland have ended with delegates reaching a compromise on how to fight global warming.
After 30 hours of deadlock, they approved a pathway to a new global climate treaty in Paris in 2015.
The agreement was achieved after a series of last minute compromises often involving single words in draft texts.
Negotiators also made progress on the contentious issue of loss and damage that developing countries are expected to suffer in a warming world.
Green groups were angry about the lack of specific commitments on finance.
The Conference of the Parties (Cop) started two weeks ago in the shadow of Typhoon Haiyan.
Speaking at the time, the lead delegate from the Philippines, Yeb Sano, drew tears in the auditorium with a heartfelt plea to "stop this climate madness".
But the good intentions foundered on the political and economic realities of a complex process where agreement has to be by consensus.
The mood was not helped by the Japanese government announcing it would not be able to meet its 2020 emissions cuts target. 'Little of substance' The Poles, tasked with chairing the talks, were criticised for being seen to be too close to the coal industry.
The head of the meeting was then sacked as environment minister in a Polish government reshuffle.
All the while there were reports from many participants that little of substance was being achieved.
There were problems with finance, compensation for loss and damage and developing a framework by which the parties would get to in Paris in 2015, the deadline for a new global deal.
The critical element was the outline framework. This proved the most difficult aspect of the negotiations as meetings continued through Friday night and late into Saturday evening. Unlike the Kyoto Protocol, the richer countries want it to apply to everyone, especially emerging giants like India and China.
However, many of the emerging countries, including Venezuela, are keen on inserting a "firewall" into the prospective agreement to preserve the past differences.
2b or not 2b? The battle centred on a single word in the pathway document.
Paragraph 2b of the text originally spoke of "commitments" by all parties. But in a plenary session, delegates from China and India ripped into this and said they could not accept the language.
"Only developed countries should have commitments," said China's lead negotiator Su Wei.
Emerging economies could merely be expected to "enhance action", he said.