Image copyright Jack Garland Image caption Gibraltar's Chief Minister Fabian Picardo wants to keep the territory in the EU

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.

Ms Sturgeon confirmed to the BBC that talks are under way with Gibraltar.

Northern Ireland could also potentially be included in the discussions.

"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.

Image copyright Getty Images Image caption Nicola Sturgeon says Scotland could now hold a second referendum on independence

More than 95% of Gibraltarians voted for Remain on Thursday. The vast majority also want to remain in the UK.

The territory overwhelmingly rejected a proposal to share sovereignty with Spain in a referendum in 2002. Mr Picardo insisted Gibraltar's status as a British Overseas Territory should not mean giving up its membership of the EU.

"The position of the people of Gibraltar is that we've expressed, perhaps even more clearly than the Scots, what our view is going forward, what should happen - that we should continue to have access to the single market to the European Union. My obligation is to protect and promote the interests of Gibraltar and to find such partners who may be willing to do the same thing within the United Kingdom."

Spain's claims

Following the referendum last week, Spain again raised the issue of joint sovereignty of Gibraltar.

"The Spanish flag on the Rock is much closer than before," Spain's acting Foreign Minister Jose Manuel Garcia-Margallo said on Friday.

But speaking in his first broadcast interview since the referendum on Thursday, Fabian Picardo said any claims by Spain to the territory would be dismissed out of hand.

"Anybody who thinks that this is a time to propose joint sovereignty or that they're going to get any millimetre of advantage in respect of the sovereignty of Gibraltar is completely wrong. They shouldn't waste their breath, they shouldn't waste their time, they shouldn't waste the time of the European people as we try to navigate this issue that has been presented to us on Friday morning."

Gabriel Gatehouse is in Gibraltar for BBC Newsnight. Watch his report on the programme at 22:30 BST on BBC Two.