Gibraltar has avoided the damaging prospect of a hard border with the EU after the UK and Spain struck a preliminary deal over the status of the tiny British territory, hours before the end of the Brexit transition period.
It means Gibraltar, off Spain’s southern tip, will now join Europe’s Schengen zone, allowing travel checks to be waived.
“We can look forward with expectation and hope," said Gibraltar Chief Minister Fabian Picardo.
"We believe we may now be able to reset our relationship with Spain and cast it in a more positive light going forward."
Spain’s Foreign Minister Arancha Gonzalez Laya said it meant that residents of Gibraltar could “breathe a sigh of relief”.
The last-minute post-Brexit trade deal agreed to by the UK and EU on Christmas Eve did not cover Gibraltar, which voted overwhelmingly to stay in the bloc in the 2016 Brexit referendum.
The territory, home to about 34,000 people, is hugely dependent on imports, which would have been severely disrupted by new Customs procedures had a solution not been found.
Britain’s Foreign Secretary, Dominic Raab, said the framework agreement had been made “following intensive discussions”.
“In the meantime, all sides are committed to mitigating the effects of the end of the transition period on Gibraltar, and in particular ensure border fluidity, which is clearly in the best interests of the people living on both sides,” Mr Raab said.
“We remain steadfast in our support for Gibraltar, and its sovereignty is safeguarded.
"I am grateful to Foreign Minister Laya and her team for their positive and constructive approach.
“We have a warm and strong relationship with Spain, and we look forward to building on it in 2021.”
Spain and Britain maintain sovereign claims over Gibraltar, which has a land area of 6.8 square kilometres.
Gibraltar's admission to the Schengen Zone means visa-free travel between members, notably Spain, where there is already immense cross-border business and leisure.
"This has not been easy and we have gone to the wire," Mr Picardo said.
"As we have been seeking to do, the treaty to be negotiated will deal with maximised and unrestricted mobility of persons between Gibraltar and the Schengen area.
"Spain as the neighbouring Schengen member state will be responsible, as regards the European Union, for the implementation of Schengen."