The European Union's two top figures, Donald Tusk and Jean-Claude Juncker, presented its 28 leaders with draft proposals at a long-delayed dinner after hours of painstaking face-to-face talks on an issue that threatened place in the union.
Shortly afterwards, Lithuanian President Dalia Grybauskaite wrote on Twitter: "Agreement #UKinEU done. Drama over."
Tusk then tweeted: "Deal. Unanimous support for new settlement for #UKinEU."
The deal paves the way for campaigning to start in earnest in Britain ahead of a referendum expected on June 23 -- and for Cameron to lead the "In" campaign.
More From This Section
The deal came after France, Belgium and eastern European countries dug in their heels over changes to areas including regulation for non-eurozone countries and benefit payments to EU migrants.
The talks that started on Thursday afternoon have dragged on for more than 30 hours as Cameron sought to cajole fellow leaders into supporting a deal.
"Negotiations are continuing into this evening. A cabinet meeting won't be possible tonight. One will be held if and when a deal is done," Cameron wrote on Twitter earlier.
Cameron was pushing for an agreement to limit the number of EU migrants coming to Britain and reassure voters that the key EU principle of ever-closer union did not apply to them.
However, eastern European countries were concerned that his plans were discriminatory and violated the EU principle of freedom of movement.
Brussels offered an "emergency brake" which Britain could invoke for a limited period if its welfare system is overwhelmed by the inflow of workers, as it believes it has been.
Cameron had said that without a satisfactory agreement, he would campaign for Britain to stay in the EU in a referendum and was prepared to walk away from the summit.