At the end of two long, fraught days of negotiations, European Union leaders agreed unanimously to a new deal that will pave the way for a referendum on Britain's continued membership in the 28-member bloc.
The news was announced late Friday night after a series of drawn-out meetings that highlighted deep divisions between the different European nations.
European Council President Donald Tusk announced on Twitter that a deal had finally been achieved.
"Deal," he declared. "Unanimous support for new settlement for #UKinEU."
David Cameron sent a tweet shortly thereafter saying: "I have negotiated a deal to give the UK special status in the EU. I will be recommending it to Cabinet tomorrow."
At a news conference shortly after the deal was signed, Cameron said he would fly back to London on Friday night and meet with his Cabinet members in the morning to inform them in person.
He is likely to also announce a date for the referendum, which is widely expected to be in June.
"This deal has delivered on the commitments I made at the beginning of this renegotiation process," Cameron said. "I believe this is enough for me to recommend the United Kingdom remain in the EU, having the best of both worlds."
Cameron achieved several of his key aims going into the summit, while having to compromise on some of the fine details.
The deal allowed Britain to impose a seven-year break on in-work welfare payments to EU migrants.
Child benefits will also be curbed for new migrants arriving in Britain, but existing EU arrivals will not be affected until 2020.
"There will be tough new restrictions on access to our welfare state for EU migrants," Cameron said. "No more something for nothing."
Britain also secured an opt out from the key EU ideal of "ever closer union" and Cameron secured protections for non-eurozone members.
"We will be in the parts of Europe that work for us," Cameron said. "And we will be out of the parts that don't work for us."
Cameron said he was addressing the "concerns of the British people" by pushing for the reforms, but they did not come easily.
The future unity of the European Union had hung precariously in the balance on Friday.
With only a few hours of sleep under their belts, Europe's politicians spent a long and frustrating day locked in intense conversation inside conference rooms.
But the talks seemed to shine a spotlight on the deep divisions that exist between the different countries, instead of their shared goals.
The Brussels summit began Thursday and Britain's so-called "Brexit" was top of the agenda, even ahead of a discussion about the continuing migrant crisis.
Thursday's daytime meetings turned into an all-nighter but still failed to produce a deal. On Friday, an early EU-wide "English breakfast," where leaders were due to fine-tune the deal, was soon pushed back turned into lunch and then dinner.
Still no deal appeared.
Many leaders are fearful that a British exit could have devastating effects for the rest of the region, but any eagerness to give Britain key concessions was tempered by a desire to protect their own national interests.
As darkness fell in Brussels, aides were told to book a second night's hotel room for their teams and Cameron issued a tweet saying "negotiations are continuing into this evening."
Cameron had spent Friday in back-to-back meetings with the Italian prime minister, the German chancellor, the Czech prime minister and his Dutch and Danish counterparts, among others.
There was also simmering frustration that Cameron was hijacking so much attention when there were pressing issues to deal with, such as the refugee crisis.
Greek Prime Minister Alexis Tsipras arrived at the summit on Friday and threatened to veto Cameron's entire deal if EU countries did not help him deal with the ever-growing numbers of refugees and migrants arriving on Greek shores.
And despite all the energy being expended on coming up with a deal, Lithuanian President Dalia Grybauskaite delivered a sobering reminder that it could all be in vain because of the upcoming vote in the U.K.
Speaking before the deal was announced, he said, "No matter what we do here, no matter what face-lifting or face-saving we perform here, it is up to the British people to decide."
Boyle is a special correspondent.
MORE FROM WORLD