UN member states reach agreement on how countries should tackle climate change, after differences cause talks to overrun by two days.