BRUSSELS - European Union leaders agreed unanimously on a package of measures aimed at keeping Britain in the 28-nation bloc at an extended summit on Friday night, European Council President Donald Tusk said.
British Prime Minister David Cameron said he had negotiated a deal to give Britain "special status in the EU" and he would recommend it to his cabinet on Saturday.
That will fire the starting gun for a fierce campaign for a referendum on Britain's future membership of the bloc expected to be held on June 23, with the outcome deeply uncertain.
Both men made their announcements on Twitter as leaders at a summit dinner reviewed an amended text that resolved outstanding disputes over welfare benefits for migrant workers from other EU countries and safeguards for Britain's financial services sector from euro zone regulation.
"Deal. Unanimous support for new settlement for #UKinEU," Tusk's message said.
The agreement delivered victory to Cameron on several of the key demands on which he chose to fight for what he called "a new settlement" with Europe.
He won a commitment to change the bloc's governing treaties in future to recognise that Britain was not bound to any political union and would have safeguards against financial regulation being imposed on the City of London by the euro zone.
Cameron earlier postponed a planned cabinet meeting to stay on in Brussels and work for a deal he can sell to sceptical voters, who are almost evenly split over whether to stay in the EU according to opinion polls.
After all-night negotiations followed by a long day of private meetings to try to whittle down remaining differences, Tusk and European Commission President Jean-Claude Juncker put an amended clean text on the dinner table and the leaders quickly indicated their acceptance.
Earlier, a plenary session to review progress was postponed several times - from a late "English breakfast" to an "English lunch" and again till dinner at 8 p.m. (1900 GMT) - and leaders were asked to book hotel rooms for an extra night in Brussels.
Facing an uphill political battle at home, Cameron was concerned to show Britons that he had won concessions that he believes can reduce an influx of EU migrant workers and keep Britain out of any future political integration.
In hours of wrangling with central and east European countries that provide many of Britain's low-paid immigrant workers, he secured the right to curb in-work benefits for up to four years and scale back child benefit for workers whose children remain abroad.