An EU summit to approve the Brexit deal will go ahead after Britain and Spain agreed on the fate of Gibraltar.
European leaders resolved a last-minute dispute over the rock Gibraltar on Saturday, clearing the way for a summit to approve a deal on Britain's withdrawal from the bloc.
Spain's Prime Minister Pedro Sanchez withdrew a threat to boycott Sunday's Brexit talks just hours before Britain's Theresa May arrived in Brussels.
May met European Commission President Jean-Claude Juncker and EU Council President Donald Tusk, and afterwards the former's spokesman Margaritis Schinas tweeted: "We are on track for tomorrow."
In his letter formally inviting the leaders of all 28 EU member states to Sunday's summit, Tusk said the deal reduces "the risks and losses resulting from the United Kingdom's withdrawal".
Later, he tweeted words from Freddie Mercury, frontman of band Queen, who died on this day 27 years ago: "Friends will be friends, right till the end."
Ahead of May's arrival, however, diplomats had scrambled for an unexpectedly intense final round of discussions.
Spain insisted on keeping a veto over future changes to EU ties with the British territory of Gibraltar, which borders Spain and which it has long claimed.
Then Britain issued a statement saying it would continue bilateral talks with Spain after Brexit on March 29, 2019 - and Sanchez relented.
"I have just announced to the King that Spain has reached an agreement on Gibraltar," he told a news conference, adding: "Spain has lifted the veto and will vote in favour of Brexit."
He claimed Britain had given ground, saying both countries "are going to have to talk about co-sovereignty".
However, May told reporters after her meeting with Juncker: "The UK's position on the sovereignty of Gibraltar has not changed and will not change.
"I am proud that Gibraltar is British and I will always stand by Gibraltar."
According to Tusk's letter, the withdrawal agreement protects citizens' rights and the Northern Ireland peace process, while ensuring Britain will keep paying EU dues during a transition period.
Alongside this, EU leaders will also approve a short political declaration Tusk said would act as a roadmap for negotiations after Brexit to "build the best possible relationship with the UK".
He emphasised that "at this critical time, the EU27 has passed the test of unity and solidarity".
In legal terms, Spain's disapproval would not have halted the divorce settlement.
But it would have been an embarrassing split for EU leaders who have proved remarkably united in the painful 17-month negotiation.
Sanchez insists that Madrid holds a veto over the fate of Gibraltar, a rocky outcrop home to a port and around 30,000 people, in post-Brexit negotiations.
London said it would not use the withdrawal agreement as cover to cut short its dialogue with Spain.
"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," May's spokesman said.
"These were constructive and we look forward to taking the same approach to the future relationship."
Any future relationship negotiated between London and Brussels will have to be approved by all remaining member states - giving Spain a de facto veto further down the line.
But May insists she will continue to negotiate on behalf of the "entire UK family" including Gibraltar.
In an angry televised statement, Gibraltar's chief minister, Fabian Picardo, compared Sanchez's tactics to those of Spain's late fascist dictator Francisco Franco.
"We do not need to wait until the start of the talks," he declared.
"I can tell Spain now: we are not interested in any dilution of our sovereignty, we are not interested in allowing for even the remotest concession to Spanish sovereignty, jurisdiction or control."
A European source said the published minutes of Sunday's summit meeting would include language stressing the importance of Britain maintaining a level playing field for business during the 21-month post-Brexit transition.
The summit will also give the European Council the lead over the Commission in negotiating future ties -- in part to reassure Madrid that its voice will be heard before any final settlement.
May will still have to sell the deal to the British parliament, an even greater political challenge.
Many of her own Conservative MPs oppose the deal, as does Northern Ireland's Democratic Unionist Party (DUP), which props up her government.
At the DUP's annual conference in Belfast on Saturday, May's former foreign minister Boris Johnson said the Brexit deal was a "historic mistake".
"The Titanic springs to mind and now is the time to point out the iceberg ahead," he said.