Spain and the United Kingdom reached a last-minute preliminary deal on the status of post-Brexit Gibraltar, the Spanish foreign minister said on Thursday.

The agreement came just hours before the UK is set to leave Europe. Without a bilateral deal, the small British territory faced a “hard Brexit,” in the words of Spain’s Foreign Minister Arancha Gonzalez Laya.

“People can breathe a sigh of relief,” said Gonzalez Laya in a news conference.

“The practical result of the deal is that the border [separating Spain and Gibraltar] will be torn down,” she said.

She explained that Gibraltar will enter into the Schengen Area, which allows free movement and no border controls within 26 European countries.

Spain, as a European member state, will be in charge of Gibraltar’s border control in the country’s port and airport. The European Border and Coast Guard Agency (FRONTEX) will also be involved, she explained, without providing details.

Gibraltar is a tiny territory located on the southern tip of the Iberian Peninsula and is home to around 32,000 people. It has no land borders with any country besides Spain.

The deal will not come into effect immediately, as it still has to pass through European and British institutions.

Gonzalez Laya said a new treaty should be signed within months. In the meantime, there will be “flexible border controls” that should not have major effects on citizens of either side of the border.

The negotiations went down to the wire, putting citizens of both Gibraltar and south of Spain on edge until almost the last possible minute.

In the 2016 Brexit referendum, 96% of voters in Gibraltar opted to remain in the EU.

“A hard border with Gibraltar would have catastrophic consequences,” Juan Franco, mayor of Spanish border town La Linea, told Spanish broadcaster RTVE on Wednesday.

“It was a long night of negotiations,” said Gonzalez Laya. “There were tough moments. We’re also negotiating in times of a pandemic, remotely, which makes it all the more complicated.”

Copyright 2022 Anadolu Agency. All rights reserved. This material may not be published, broadcast, rewritten, or redistributed.