More than 95% of residents in Gibraltar voted to remain in the EU in the referendum
Spain is threatening to reject the UK's Brexit deal unless last-minute changes are made over Gibraltar.
The Spanish government is unhappy that the draft agreement states that any future issues on trade and security in Gibraltar will be dealt with by the UK and EU.
Spain wants to negotiate its own deals concerning Gibraltar with the UK and doesn't want any EU deals to apply automatically without its agreement.
Spain's Foreign Minister Josep Borrell warned that the draft deal does not spell out specifically how Gibraltar should be handled.
Speaking after talks in Brussels, Mr Borrell said: "We want the interpretation to be clear in that text that the negotiations between the United Kingdom and the EU will not apply to Gibraltar."
"What is being negotiated has a territorial scope that does not include Gibraltar, the future negotiations on Gibraltar are separate."
He said until this is clarified in the Brexit deal Spain will not back the agreement.
Spain can't single-handedly block Theresa May's Brexit deal but it does complicate matters for the Prime Minister.
The deal has to be decided by a majority vote, meaning Spain doesn’t have a veto, but realistically Brussels will want all of the member states to back the agreement.
A spokesperson for Theresa May said: "The draft withdrawal agreement agreed last week covers Gibraltar.
"The PM has been clear that we will not exclude Gibraltar and the other overseas territories and crown dependencies from our negotiations on the future relationship.
"We will get a deal that works for the whole UK family."
Gibraltar’s chief minister Fabian Picardo says he isn't surprised the Spanish Government is raising issues at the last minute.
“The position taken by the Spanish Government today does little to build mutual confidence and trust going forward."
He said, " The language of vetos and exclusions should be the language of the past. It has no place in the modern Europe of today at a time when both the UK and Gibraltar are trying to build a new positive future relationship with the EU."
Spain's threat to scupper that deal coincides with the signing of another, the Armed Forces Gibraltar Act, underlining the security relationship between the British military and local police.
Armed Forces Minister Mark Lancaster says it re-affirms Britain's support for Gibraltar, the document was signed on board the Royal Navy destroyer HMS Diamond.