Madrid and London were today negotiating against the clock to preserve the free movement of people across the border between Spain and Gibraltar once the Brexit transition period ends on 31 December.
Although Britain reached a last-minute exit deal with the European Union on Christmas Eve, it does not cover Gibraltar, the British territory on Spain's southern tip which is historically claimed by Madrid.
If no agreement is reached, there are serious concerns that a "hard border" would cause disruption for the workers and businesses on both sides of what will be a new border between Britain and the European Union.
"We will seek this agreement until the last minute," Spanish Foreign Minister Arancha Gonzalez Laya said today when asked about the talks, which also involve the Gibraltar government.
If there is no deal, Gibraltar will be "the only place where a hard Brexit is applied", which would lead to tighter border controls, she warned.
Gibraltar's Chief Minister Fabian Picardo said on Sunday that he remained "optimistic" that an agreement will be reached.
Around 15,000 people live in Spain and work in Gibraltar, accounting for half of the territory's workforce centred mainly on the tourism, financial services and online gambling sectors.
These cross-border workers will be exempt from border controls even if no agreement on free movement is reached as long as they have registered their status with Gibraltar by 1 January.
Over 8,500 people have so far signed up, according to the Spanish foreign minister.
But this would leave out the roughly 10 million tourists, mainly day-trippers from Spain, who visit Gibraltar each year, drawn in part by its duty-free shopping.
Along with gambling and offshore banking, tourism is a cornerstone of the economy for Gibraltar, one of the most prosperous regions in Europe which is home to 34,000 people.
Visitors from the European Union to Gibraltar currently need only to show their national identity documents, first to Spanish border police and then to those in the British territory.
However, after 1 January they will have to have their passports stamped, which a Gibraltar government source told AFP will cause "queues lasting hours".
And the movement of goods between Gibraltar and Spain will be subject to tighter customs procedures from 1 January, with unwanted economic consequences.
With a land area of just 6.8 square kilometres, Gibraltar imports all of its food.
In the event that no deal is reached, Gibraltar has extended its port facilities to be able to handle more ships and has contracted a ferry service to bring goods from the nearby Spanish port of Algeciras.
Mayors of Spanish cities in the economically depressed region that surrounds Gibraltar warned in a joint statement that a lack of an agreement would have "dire economic, political and social consequences" for them.
Gibraltar businesses imported around €421 million in goods and services from Spain in 2013, while Spanish cross-border workers earned over £100 million that year, according to a Gibraltar Chamber of Commerce study.
It would be best for Gibraltar, Spain and Britain to keep the border "as free and frictionless as possible," said John Fletcher, an economist at Britain's Bournemouth University who prepared the report.
"And that is as important for Spain as for Gibraltar, in fact probably more important for Spain," he told AFP.
While Spain ceded Gibraltar to Britain in perpetuity in 1713 following a military struggle, Madrid has long wanted it back in a thorny dispute that has for decades caused friction on the frontier.
Tensions peaked in 1969 when the regime of dictator Francisco Franco closed the border, which did not fully reopen until 1985.