Spain’s prime minister has threatened to scupper Theresa May’s Brexit deal – with a warning that “our positions remain far away” on the issue of Gibraltar.

Pedro Sanchez spoke to his British counterpart on Wednesday night, and Mrs May subsequently said she was “confident that we’ll be able to agree a deal that delivers for the whole UK family, including Gibraltar”.

But in a late-night tweet on Thursday, Mr Sanchez appeared to disagree, writing: “After my conversation with Theresa May, our positions remain far away.

“My government will always defend the interests of Spain. If there are no changes, we will veto Brexit.”

Spain does not have the ability to “veto Brexit” or the 26-page withdrawal agreement, which will be adopted by a qualified majority, rather than a unanimous vote.

But any refusal to co-operate would undoubtedly sour the atmosphere at this weekend’s EU summit, where leaders from the trading bloc are aiming for consensus.

Spain wants any declaration on a new EU-UK relationship to make clear that any decisions about Gibraltar, a disputed British overseas territory, would only be taken in direct talks with Madrid.

An original clause in the draft deal said any post-Brexit agreement between the UK and the EU could only apply to Gibraltar if it was negotiated on a bilateral basis with Spain, but this clause has since disappeared from the final text.

The eleventh-hour objections may mean that the agreement is not ready until the last minute.

Gibraltar is a tiny 2.6 square mile (6.8 square kilometre) territory that is home to about 30,000 people.

The territory’s chief minister, Fabian Picardo, says he is hopeful of a breakthrough soon – with Mrs May due to head to Brussels on Saturday for closing talks with European Commission President Jean-Claude Juncker.

Mr Picardo told Sky News: “I think everybody wants to achieve this very difficult thing by consensus, and I think it will be possible to achieve that consensus and I certainly hope that it will be possible to do that in a way that doesn’t delay the summit on Sunday.”

He also warned that he believes Brexit will be “bad for Britain and bad for Gibraltar”, adding: “My view is that we should not be doing Brexit at all. But if the United Kingdom is doing Brexit, we’re doing Brexit too – because what’s best for Gibraltar is that we stick with the United Kingdom.”

Spain is not the only major obstacle for Mrs May, who is enduring an uphill struggle to win the support of her own MPs.

On Thursday, she faced hostile criticism from prominent Conservative backbenchers and the Democratic Unionist Party (DUP) in a dramatic Commons showdown.

It took 39 minutes of debate before her first positive response to the latest agreement, with Labour leader Jeremy Corbyn describing it as “26 pages of waffle” that amounted to a “vague menu of options”.

Mrs May’s critics in Westminster have been lining up to demand that she removes a central part of the withdrawal treaty: the Irish backstop.

Iain Duncan Smith called for the backstop, which would keep the whole of the UK in a customs union if a free trade agreement cannot be negotiated by the end of 2021, to be “stripped out” – warning “none of this is at all workable”.

Dominic Raab, who quit as Brexit secretary last week, added the “regrettable but inescapable reality” of the backstop was that it “gives even more away” to Brussels.

And the DUP, which is propping up Mrs May’s government, gave her an ultimatum.

Sir Jeffrey Donaldson, the party’s chief whip, told a silent Commons: “If she wants to have the support of my party… then we need to see an end of the backstop.”