European Council President Donald Tusk has recommended that the EU approve the Brexit deal at a summit on Sunday.
It comes after Spanish PM Pedro Sanchez received assurances from the UK government over Gibraltar, and dropped his threat to boycott the summit.
He said he had received the written guarantees he needed over Spain’s role in the future of the British territory.
UK Prime Minister Theresa May flies into Brussels later to hold talks with top EU officials, ahead of the summit.
Meanwhile, former UK Foreign Secretary Boris Johnson said the UK would become a “satellite state” under the deal.
The UK is scheduled to leave the EU on 29 March 2019.
The terms of the UK’s withdrawal have been under negotiation since June 2016 following a referendum in which 51.9% voted to leave the EU.
Even if the EU approves the deal, it still has to be passed by the UK Parliament, with many MPs having stated their opposition.
Spain had raised last-minute objections ahead of the summit about how the issue of Gibraltar had been handled in the Brexit talks so far.
But EU leaders secured a compromise with the Spanish prime minister, who said that Europe and the UK “had accepted the conditions set down by Spain” and so would “vote in favour of Brexit”.
Mr Tusk, who represents EU leaders on the world stage, said he recommended “that we approve on Sunday the outcome of the Brexit negotiations” in a letter to members of the European Council.
He added: “No-one has reasons to be happy. But at least at this critical time, the EU 27 has passed the test of unity and solidarity.”
What will happen at the summit?
Mrs May will meet the president of the European Commission, Jean-Claude Juncker, and Mr Tusk for talks later.
Then on Sunday, EU leaders will meet for the special Brexit summit. They will be asked to approve two key Brexit documents:
The political declaration, which sets out what the UK and EU’s relationship may be like after Brexit – outlining how things like UK-EU trade and security will work
The EU withdrawal agreement: a 585-page, legally-binding document setting out the terms of the UK’s exit from the EU. It covers the UK’s £39bn “divorce bill”, citizens’ rights and the Northern Ireland “backstop” – a way to keep the border with the Republic of Ireland open, if trade talks stall.
There is no formal vote on Sunday but the EU expects to proceed after reaching a consensus.
What happens afterwards?
If the EU signs off the withdrawal deal, Mrs May will then need to persuade MPs in the UK Parliament to back it.
The former foreign secretary said the UK was on the verge of “making a historic mistake”, adding that “we will find that Brussels has got us exactly where they want us – a satellite state”.
Mr Johnson told the Northern Ireland’s Democratic Unionist Party (DUP) conference that the EU had made Northern Ireland an “indispensable bargaining chip” in the Brexit negotiations.
Please upgrade your browser
Your guide to Brexit jargon
Mrs May relies on the support of the DUP’s 10 MPs in key votes because she does not have a majority in the House of Commons.
The DUP opposes the Brexit deal because of the “backstop” – the back-up plan to make sure a hard border between Northern Ireland and the Republic of Ireland never happens.
It will only come into effect if the UK and EU fail to agree a long-term trade deal. But the backstop would mean that Northern Ireland – but not the rest of the UK – would still follow some EU rules on things such as food products.
DUP leader Arlene Foster told her party conference that the prime minister had not been able to guarantee that the backstop would not have to be used.
What else has the government said?
Chancellor Philip Hammond insisted that the prime minister’s Brexit deal is better than remaining in the EU.
He said the deal respected the result of the 2016 referendum and offered “the best compromise possible”.
He added that he was hopeful of a solution with the DUP.
On Friday, the PM said the UK should not hope for a “better deal” from the EU if MPs reject her Brexit agreement.
But Mrs May declined to say whether the UK would be better off outside the EU, saying only it would be “different”.
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.