Theresa May has given way to Madrid’s demands over the future of Gibraltar after the Spanish prime minister threatened to “veto” the Brexit deal due to be signed off by EU leaders on Sunday.

On the eve of Sunday’s special Brexit summit, the British ambassador to the EU, Sir Tim Barrow, wrote to concede that Gibraltar would not necessarily be covered by a future trade deal with the EU.

The development gives Spain a veto over Gibraltar benefiting from a future trade and security agreement between Brussels and the British government.

The Spanish leader, Pedro Sánchez, reacted immediately, claiming the UK would now have to open talks on “joint sovereignty” of Gibraltar, over which Spain has had a claim since the military dictatorship of Francisco Franco.

Sánchez said: “Once the UK has left the EU, Gibraltar’s political, legal and even geographic relationship with the EU will go through Spain …

“Spain will be a fundamental pillar of the relationship between Gibraltar and the EU as a whole.

“When it comes to the future political declaration, the European council and the European commission have backed Spain’s position, and backed it as never before.

“In these fundamental future negotiations, we’re going to have to talk about joint sovereignty and many other things with the UK.”

The 27 EU member states are set to publish a further statement in solidarity with Spain at the summit, according to a leaked document seen by the Guardian.

“After the United Kingdom leaves the union, Gibraltar will not be included in the territorial scope of the agreements to be concluded between the union and the United Kingdom,” the EU will say.

In the statement, the EU will go on to warn that any separate deal to protect Gibraltar’s economy will “require a prior agreement of the Kingdom of Spain”.

The news was met with anger by politicians across the political spectrum. The Liberal Democrat’s Brexit spokesman, Tom Brake MP, said: “The prime minister has caved in once again. In a desperate bid to get her disastrous deal across the line, May appears to have cast the people of Gibraltar aside.

“She has conceded that Gibraltar won’t necessarily be covered by a future trade deal, simply another example of why what she has negotiated is completely unacceptable. She has left the status of Gibraltar in jeopardy.

“This is a day of shame. The only way to sort out this chaos would be through a People’s Vote, with the option to remain in the EU”.

Labour’s MEP for Gibraltar, Clare Moody, said: “What is remarkable is that Theresa May has gone to Brussels to concede further text at this stage, before we’ve even left.”

The Conservative MP, Andrew Bridgen, said: “It appears that there is no-one the prime minister will not betray to achieve her sell-out deal”.

Amid the growing outcry over the concession, the prime minister, insisted that nothing had changed over the UK’s territorial claim to Gibraltar, as she visited Brussels on Saturday night for meetings with EU officials, including European commission president, Jean-Claude Juncker.

May also dismissed claims from Spain’s foreign minister that the agreement on the Rock had been a victory for Madrid delivering a treaty that was “the most important one since the Utrecht Treaty of 1713”, which had handed the territory to the British.

May said: “The UK’s position on the sovereignty of Gibraltar has never changed and will not change.

“I’m proud Gibraltar is British and I will always stand by Gibraltar. The UK’s position on Gibraltar has not changed and will not change.

“We have negotiated on behalf of Gibraltar, they are covered by the whole withdrawal agreement and by the implementation period. In the future we will continue to negotiate on behalf of the whole UK family and that includes Gibraltar. I’m proud Gibraltar is British I will always stand by Gibraltar.”

The move does, however, resolve the final outstanding issue in the Brexit negotiations. Donald Tusk, the European council president, sent a letter of invitation to Sunday’s summit to all the leaders on Saturday afternoon.

Tusk wrote: “During these negotiations, no one wanted to defeat anyone. We were all looking for a good and fair agreement. And I believe that we have finally found the best possible compromise.

“Given all of the above, I will recommend that on Sunday we approve the outcome of the Brexit negotiations. And although no one will have reasons to be happy on that day, there is one thing I would like to stress: at this critical time, the EU27 has passed the test of unity and solidarity.”

The development threatens, however, to open up a new front in Downing Street’s battle with the critics of May’s deal.

Sánchez had demanded a written assurance as the price for his support for the withdrawal agreement and accompanying political declaration on the future relationship.

Spain does not have a formal veto over the 585-page withdrawal agreement and the 26-page joint declaration by the leaders, but the EU would have been unlikely to go ahead with the summit without Madrid’s support.

The prime minister had promised in the House of Commons and on the steps of Downing Street that she would work for the entire “UK family”, including Gibraltar – a disputed territory.

Spain has always insisted that Gibraltar could only be covered by any agreements struck between the EU and the UK with Madrid’s consent.

A bilateral agreement on tax evasion, police cooperation and tobacco smuggling had persuaded Spain that Gibraltar could be covered by the 21-month transition period after Brexit, during which the UK would stay in the single market and customs union without representation in EU decision-making institutions.

Spain was furious when an article in the withdrawal agreement appeared to suggest that any future trade deal would cover Gibraltar. Downing Street was accused of “acting under the cover of darkness” in inserting the clause.

The letter from the British ambassador to the European council laid down Downing Street’s understanding that article 184 in the withdrawal agreement “imposes no obligations regarding the territorial scope” of a future trade deal.

A separate letter made public on Saturday, from Jean-Claude Juncker, the president of the European commission, and Tusk, said the two EU leaders wanted to “underline our solidarity with the Kingdom of Spain on this matter”.

Tusk spoke to Sánchez on Saturday afternoon to ensure that he was content.

When asked if this was a British climbdown, a UK government spokesman said: “No. This is the same position as for the first phase of the negotiations. We will negotiate outcomes which work for the EU and the whole of the UK family.”