EU leaders will meet tomorrow to endorse the Brexit deal after 11-hour diplomatic haggling to bring Spain on board.

Spanish prime minister Pedro Sanchez had been threatening to scupper the summit over concerns on Gibraltar but he has agreed to attend after securing written assurances from UK diplomats and speaking to senior European figures.

On the eve of the summit the UK ambassador to the EU, Sir Tim Barrow, wrote to reassure Madrid that Gibraltar would not necessarily be covered by future trade arrangements after Brexit, leading Mr Sanchez to claim that Britain would be forced to open talks on “joint sovereignty” with Spain.

Arriving for the summit in Brussels, Ms May said Gibraltar was “covered by the whole withdrawal agreement”, and that she would always “stand by’’ its citizens.

European Council president Donald Tusk announced the summit would go ahead on Twitter, saying: “I will recommend that we approve on Sunday the outcome of the Brexit negotiations.

“No one has reasons to be happy. But at least at this critical time, the EU27 has passed the test of unity and solidarity.”

Negotiators were at work throughout the night to broker a deal to reassure Spain over Gibraltar without reopening the withdrawal text, which both London and Brussels consider to be agreed.

Mr Sanchez confirmed that a deal had been reached, allowing invitations to be sent to the remaining EU leaders for the special summit, where Theresa May is hoping to get her Brexit blueprint approved.

The row centres on Spain’s claims that the future relationship to be negotiated between the EU and UK should not apply to Gibraltar and that it should only be decided between itself and Britain.

But Ms May said the plan must apply to “the whole United Kingdom family”, which appears to include Gibraltar, which has been a British overseas territory since the 18th century.

British diplomats have broken the impasse by confirming the government’s position that a future trade deal will not automatically cover Gibraltar.

A UK government spokesman said: “For the withdrawal negotiations, given there are some circumstances which are specific to Gibraltar, we held talks with Spain which directly involved the government of Gibraltar.

“These were constructive and we look forward to taking the same approach to the future relationship.”

Mr Sanchez said “this is going to allow us to have direct negotiations with the UK regarding Gibraltar”. He added: “Once the UK has left the EU, Gibraltar’s political, legal and even geographic relationship with the EU will go through Spain.”

Cabinet ministers resign over Brexit deal Show all 13 1 /13 Cabinet ministers resign over Brexit deal Cabinet ministers resign over Brexit deal Esther McVey Britain's Work and Pensions Secretary Esther McVey arrives to attend the weekly meeting of the cabinet at 10 Downing Street in London. - Britain's Work and Pensions Secretary Esther McVey resigned from the cabinet over draft Brexit deal AFP/Getty Cabinet ministers resign over Brexit deal Handout image taken from the Twitter feed of @EstherMcVey1 of the resignation letter addressed to Prime Minister Theresa May from Works and Pensions Secretary Esther McVey. PRESS ASSOCIATION Photo. Issue date: Thursday November 15, 2018. Ms McVey has resigned, saying the Brexit deal âdoes not honour the result of the referendumâ. See PA story POLITICS Brexit. Photo credit should read: @DominicRaab/PA Wire NOTE TO EDITORS: This handout photo may only be used in for editorial reporting purposes for the contemporaneous illustration of events, things or the people in the image or facts mentioned in the caption. Reuse of the picture may require further permission from the copyright holder. PA Cabinet ministers resign over Brexit deal Dominic Raab British Brexit Secretary Dominic Raab give a press conference at the end of the final round of talks in Brexit negotiations at the European Commission in Brussels, Belgium EPA Cabinet ministers resign over Brexit deal Handout image taken from the Twitter feed of @DominicRaab of the resignation letter addressed to Prime Minister Theresa May from Brexit Secretary Dominic Raab. PRESS ASSOCIATION Photo. Issue date: Thursday November 15, 2018. Mr Raab has resigned, saying he âcannot in good conscience support the terms proposed for our deal with the EUâ. See PA story POLITICS Brexit. Photo credit should read: @DominicRaab/PA Wire NOTE TO EDITORS: This handout photo may only be used in for editorial reporting purposes for the contemporaneous illustration of events, things or the people in the image or facts mentioned in the caption. Reuse of the picture may require further permission from the copyright holder. PA Cabinet ministers resign over Brexit deal Rehman Chrishti Vice Chairman of the Conservative Party Rehman Chrishti tendered his resignation letter this afternoon PA Cabinet ministers resign over Brexit deal Cabinet ministers resign over Brexit deal Anne-Marie Trevelyan Parliamentary private secretary in the Department of Education Anne-Marie Trevelyan resigned stating that she cannot support the deal Cabinet ministers resign over Brexit deal Handout image taken from the Twitter feed of @annietrev of the resignation letter addressed to Prime Minister Theresa May from Anne-Marie Trevelyan, a parliamentary private secretary in the Department for Education. PRESS ASSOCIATION Photo. Issue date: Thursday November 15, 2018. Ms Trevelyan has resigned saying she cannot support the Brexit deal after negotiations âbuilt on the UK trying to appease the EUâ. See PA story POLITICS Brexit. Photo credit should read: @annietrev/PA Wire NOTE TO EDITORS: This handout photo may only be used in for editorial reporting purposes for the contemporaneous illustration of events, things or the people in the image or facts mentioned in the caption. Reuse of the picture may require further permission from the copyright holder. PA Cabinet ministers resign over Brexit deal Sam Gyimah Universities minister Sam Gyimah resigned on November 30, claiming the government's decision to pull out of the EU's Galileo satellite navigation system as a deciding factor PA Cabinet ministers resign over Brexit deal Shailesh Vara Shailesh Vara who has quit as Minister of State for Northern Ireland, saying he cannot support Theresa May's Brexit agreement, which he said "leaves the UK in a halfway house with no time limit on when we will finally be a sovereign nation" PA Cabinet ministers resign over Brexit deal Cabinet ministers resign over Brexit deal Suella Braverman Brexit minister Suella Braverman has resigned, stating “It is not what the British people, or my constituents, voted for in 2016.” Cabinet ministers resign over Brexit deal Ranil Jayawardena Parliamentary private secretary to the ministry of justice Ranil Jayawardena resigned as he could not back the deal "in good conscience"

The prime minister was due to head to Brussels on Saturday for last-minute talks on selling her deal with Mr Tusk and European Commission president Jean-Claude Juncker.

However, she still faces major opposition at home, with both Boris Johnson and her DUP allies urging her to “bin” the deal.