The EU will back Spain over its territorial claims to Gibraltar in the next phase of Brexit negotiations by giving Madrid the power to exclude the British overseas territory from any trade deal struck with Brussels.

The Observer has learned that the Spanish government has insisted on reference to the Rock in the EU’s opening negotiating position, which will be published in draft form on Monday.

Boris Johnson will be presented with the choice of reaching agreement with the Spaniards about Gibraltar’s future or exposing its citizens to economic peril by pushing it outside any EU-UK trade deal.

“They have in principle asked that the new relationship not apply to Gibraltar without the explicit consent of Spain, which will only be given if the bilateral talks with Spain and the UK over the rock are resolved,” a senior EU diplomat said.

The development highlights the pitfalls Downing Street faces as it moves into negotiations on the future relationship with Brussels. The UK is now a “third country” to the EU after it formally withdrew at midnight central European time on Friday.

British sovereignty over Gibraltar was formalised by the treaty of Utrecht in 1713 but Spain has always bristled at the idea of UK ownership.

As an EU member state, the UK had been able to resist Spanish claims over the territory but Madrid will now have the full support of the other 26 countries in the bloc.

A foreign office spokesperson said: “The UK will not exclude Gibraltar from our negotiations in relation to our future relationship with the EU. We will negotiate on behalf of the whole UK family, which includes Gibraltar.”

Negotiations with the EU are expected to start on 3 March. In an interview with this newspaper, Mairead McGuinness, an Irish MEP who is vice-president of the European parliament, said: “I think we are all hoping for the best and not sure if it is going to happen or not.

“I expect there will be some shadow boxing for a bit. But if people are sensible and politics works then we should be able to achieve a framework of an agreement by the end of the year. The details perhaps not so on many areas.

“There are so many areas where we work together today and we don’t even realise because they have been established over those 47 years of partnership. And once you have left, you are not in the club.

“When Europe does set out its stall on the future relationship I think people should read it carefully and reflect on the fact that when we were negotiating on the withdrawal agreement we stuck with the issues that were core to us.”

Play Video 2:28 'Why does everyone want to divide us?': EU presidents bid adieu to the UK – video

McGuinness said she expected Michel Barnier to maintain the unity of the EU’s member states in the next phase. “I think where we have strength is in our negotiating skills; the number of people we have who have been negotiating trade deals forever,” she said. “While people criticise the EU for bureaucracy, its clarity is in its written word.”

McGuinness chaired part of the debate in the parliament last week before MEPs’ ratification of the withdrawal agreement during which she was forced to reprimand Nigel Farage and his Brexit party MEPs for waving union flags, in breach of the chamber’s rules.

“I will be the first to admit that Nigel Farage has succeeded,” McGuinness said. “It took him 20 years and he has used the platform for the European parliament to achieve that.

“I regret the loss of the British MEPs, particularly the ones who work in committee,” she added. “I have no experience of the Brexit party MEPs in committees. I don’t think they did anything in committees. They tended just to come into the plenary session for the ‘YouTube moment’ and they did it well.”