Gibraltar is in talks with Scotland about a plan to keep parts of the UK in the EU, BBC Newsnight has learned.
Fabian Picardo, the territory's chief minister, told the BBC he was speaking to Scotland's First Minister, Nicola Sturgeon, about various options.
One possibility under discussion is for Gibraltar and Scotland, which both voted to remain in the EU, to maintain the UK's membership of the bloc.
Northern Ireland could also potentially be included in the talks.
"I can imagine a situation where some parts of what is today the member state United Kingdom are stripped out and others remain," Mr Picardo told Newsnight.
"That means that we don't have to apply again for access, we simply remain with the access we have today, and those parts that leave are then given a different sort of access, which is negotiated but not necessarily under Article 50," he said, referring to a provision in the Lisbon Treaty that sets out how a member state can voluntarily leave the Union.
Past precedents
There is a precedent for such a proposal. Denmark joined what was then the EEC in 1973, the same year as the UK and Ireland.
Greenland gained autonomy from Denmark in 1979 and seceded from the EU in 1985, following a referendum three years earlier.
Nicola Sturgeon has previously said that a second referendum on independence for Scotland is "highly likely", following last Thursday's Leave victory.