COP17 was extended from Friday and after more talks overt the weekend the agreement was reached late on Saturday.
This means that the European Union will follow the request of developing countries to place its current emission-cutting pledges inside the legally-binding Kyoto Protocol.
Talks on a new legal deal covering all countries will begin next year and end by 2015, coming into effect by 2020. Management of a fund for climate aid to poor countries has also been agreed, though how to raise the money has not.
South Africa's International Relations Minister, Maite Nkoana-Mashabane, said. "We came here with plan A, and we have concluded this meeting with plan A to save one planet for the future of our children and our grandchildren to come. We have made history."
The EU and India had a feisty battle over the "roadmap" for a new global deal. India did not want the deal to be legally binding but it was resolved in the end with the deal including "legal force".
The big four countries, Brazil, South Africa, India and China felt they were pressured to much. The tight timetable and excessive legality was a problem for them.
India called for equity and it believes in maintaining the current stark division where only countries labelled "developed" have to cut their greenhouse gas emissions. Western nations, she said, have not cut their own emissions as they had pledged; so why should poorer countries have to do it for them? Xie Zhenhua, head of the Chinese delegation, agreed.
A management framework was adopted for the Green Climate Fund, which will eventually gather and disburse finance amounting to $100bn (£64bn) per year to help poor countries develop cleanly and adapt to climate impacts.