Spain's Prime Minister Pedro Sanchez had threatened to boycott Sunday’s EU Brexit summit but now says he will go to Brussels and support the Brexit deal after London and Madrid agreed to direct post-Brexit talks over the future of Gibraltar.
European leaders resolved a last-minute dispute over the future of Gibraltar on Saturday, clearing the way for a summit to approve the Brexit deal.
Spain's Prime Minister Pedro Sanchez withdrew a threat to boycott Sunday's European Council just hours before Britain's Theresa May was due in Brussels.
The British premier plans to meet EU leaders Jean-Claude Juncker and Donald Tusk, even though diplomats say the agreement is ready for EU leaders to approve.
Ahead of her arrival, diplomats had scrambled for an unexpected intense final round of discussion, after Spain insisted on keeping a veto over future changes to EU ties with Gibraltar.
Then Britain issued a statement saying it would continue bilateral talks with Spain after Brexit on March 29 - and Sanchez relented.
"I have just announced to the King that Spain has reached an agreement on Gibraltar," he told a news conference.
"The European Council will therefore be held tomorrow. Europe and the United Kingdom have accepted Spain's demands. Spain has lifted the veto and will vote in favour of Brexit."
Even as Sanchez was speaking, the president of the European Council Donald Tusk was finally able to issue his letter inviting the leaders of EU member states to Sunday's summit.
"I will recommend that on Sunday we approve the outcome of the Brexit negotiations," Tusk said, saying the deal on the table reduces "the risks and losses resulting from the United Kingdom's withdrawal."
"And although no-one will have reasons to be happy on that day, there is one thing I would like to stress: at this critical time, the EU27 has passed the test of unity and solidarity."
According to Tusk's invitation, 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 the withdrawal treaty, a second short political declaration will also be approved on Sunday.
This, Tusk said, will act as a roadmap for negotiations after Brexit day on March 29 to "build the best possible relationship with the UK after Brexit, as friends and partners."
So far, nothing in the painful 17-month withdrawal process has gone smoothly, and on Friday, Sanchez insisted that Madrid holds a veto over the fate of Gibraltar in post-Brexit negotiations.
"If there's no agreement ... there very probably won't be a European Council," he declared, referring to Sunday's summit of 27 EU leaders ahead of their encounter with May.
Gibraltar, a rocky outcrop home to a port and around 30,000 people, is a British territory claimed by Spain and a bone of contention as London negotiates a new relationship with Brussels after Brexit on March 29.
On Saturday, as the dispute threatened to derail the summit, London issued a statement saying Number 10 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."
In legal terms, Spain's disapproval would not have halted the divorce settlement, but it would embarrass EU leaders keen to show that the 27 are united, and might delay Sunday's largely symbolic summit.
TRT World's Kevin Ozebek has more from Brussels.
And any final relationship negotiated between London and Brussels after Brexit day on March 29 would have to be approved by all remaining member states - giving Spain a de facto veto further down the line.
May is due in Brussels later on Saturday to see EU Commission president Juncker, head of the bloc's executive, and Tusk, whose institution represents the member states.
But European diplomats told AFP no more substantive negotiations are planned for this weekend and it was hoped Sunday's summit would simply see leaders sign off on the fruit of 17 months of dialogue.
A European source said the meeting's minutes 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 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.
After that, May will still have to sell the deal to the British parliament, an even greater political challenge.
May has refused to say whether she would resign if parliament eventually votes down the divorce agreement, but the political temperature in Westminster has reached boiling point.