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.
With time running out, desperate ministers and their advisers huddled in the corner of the hall to work out a compromise.
After an hour, they agreed to change "commitments" to "contributions".
The more flexible word allows the US and EU to insist that everyone is on the same page, while also allowing China and India to insist that they are doing something different from the richer countries.
EU Climate Commissioner Connie Hedegaard was relieved that this key element had been agreed.
"It is extremely challenging, but we got the process on track," she told BBC News.
"There are more beautiful and faster ways to Paris but what is important here is that we get there and get a good outcome, I think that is doable after what I have seen here.
Another key battle was over the issue of loss and damage. This was crucial for developing countries which say that money to help them adapt to climate change is all well and good, but they need something extra to cope with extreme events such as Typhoon Haiyan.
They had argued for a new institution called a loss-and-damage mechanism that would have the financial clout to deal with the impacts of events that had been clearly affected by climate change.
But in the text the new mechanism would have to sit "under" an existing part of the UN body that dealt with adaptation.
This one word stuck in the throats of delegates from developing countries, including Filipino Yeb Sano who again made a moving intervention.
"It has boiled down to one word and I would say this is a defining moment for this process. Let us take that bold step and get that word out of the way."
After another huddle the word was changed and the text accepted.
Not everyone was happy.
Harjeet Singh from Action Aid said the new mechanism was merely fulfilling a pledge made last year.
"It is the barest minimum that was supposed to be achieved at Warsaw on loss and damage anyway. A few rich countries including the US held it hostage till the very end," he said.
By themselves, these compromises are not major breakthroughs and delegates know that far bigger battles lie ahead.
"As the Rolling Stones said, 'you don't always get what you want'," said Alden Meyer, from the Union of Concerned Scientists.
"But sometimes you get what you need if you try hard enough."