EU leaders have agreed a deal in Brussels which will pave the way for an in/out referendum in the UK before the summer.

The development came late on the second day of gruelling talks in Brussels between leaders of the 28 member-states, which saw the Prime Minister face opposition to proposals to restrict migrant benefits and provide new protections for countries outside the single currency.

Lithuanian president Dalia Grybauskaite broke the news in a tweet from the round-table discussions: "Agreement #UKinEU done. Drama over."

And Danish PM Lars Lokke Rasmussen said: "David Cameron fought hard for Britain. Good deal for UK and for EU. Congrats!"

Minutes later, the breakthrough was officially confirmed by European Council president Donald Tusk, who said: "Deal. Unanimous support for new settlement for UK in EU."

Mr Cameron said: "I have negotiated a deal to give the UK special status in the EU. I will be recommending it to Cabinet tomorrow."

The agreement clears the way for the PM to return immediately to London and call a special Cabinet meeting on Saturday to endorse the deal and set a date for the long-awaited referendum - widely expected to come on June 23.

The meeting will also give a green light to Eurosceptic ministers like Iain Duncan Smith and Chris Grayling to go out and campaign for Britain to leave Europe, and put pressure on waverers like London mayor Boris Johnson to spell out where they stand.

The deal came after behind-the-scenes talks which stretched through Thursday night and most of Friday, as Mr Cameron and Mr Tusk struggled to keep Britain's renegotiation on track.

The 28 leaders had initially been due to gather early in the morning for an "English breakfast" meeting to approve a package of reforms to the UK's membership, but breakfast became brunch, lunch, high tea and then dinner as opponents of the deal dug in their heels.

The delays forced Mr Cameron to scrap plans to summon ministers for a Cabinet meeting on Friday evening.

Mr Cameron had faced concerns from eastern European countries like Poland, Hungary, the Czech Republic and Slovakia over his call for an "emergency brake" on in-work benefits for migrant EU workers to extend for as long as 13 years.

And the same nations put up stiff resistance to the UK's demand to impose cuts in child benefits for offspring living abroad on 34,000 existing claimants as well as future migrants.

Leaked copies of the deal indicated that a compromise deal will allow existing claimants to carry on receiving child benefit in full for offspring living overseas until 2020, but that all member states will then be able to pay them at the rate of their home country.

This rate - usually lower than that paid to British parents - will be applicable immediately to all new migrants whose children live abroad after the agreement comes into force.

The agreement falls well short of the outright ban on sending child benefit abroad initially demanded by Mr Cameron, and marks a compromise solution with eastern states who had insisted that all 34,000 existing claimants in the UK should continue to receive the full payment until their sons and daughters reach adulthood - something rejected as "not acceptable" by the PM.

A lengthy section making clear that the phrase "ever closer union" in EU treaties is not "in legal terms an equivalent to political integration" was struck out, in an apparent response to Belgian sensitivities. But the new text makes clear that EU treaties will be amended to make clear that references to ever closer union "do not apply to the United Kingdom".

An "emergency brake" on in-work welfare payments for migrant workers will be made available for seven years - with no option for extensions - in cases where member states are facing excessive strain from new arrivals.

The seven year period is shorter than the 13 years put forward by Mr Cameron in negotiations, but considerably longer than eastern European nations had argued for.