"Britain's commitment to Gibraltar is absolute, it's unshakable and it will endure whatever the decision in the referendum," Foreign Secretary Philip Hammond said referring to a June 23 referendum on Britain's membership of the European Union.
"But I have to say this. Britain's ability to protect Gibraltar's interest will be seriously impaired if we are no longer members of the European Union, if we are no longer sitting around the table in Brussels when the decisions are made," he added.
Spain ceded Gibraltar to Britain in perpetuity in 1713 but has long argued that it should be returned to Spanish sovereignty.
The possibility of Britain leaving the EU is raising alarm bells in Gibraltar, where many of the tiny territory's 33,000 residents fear it threatens their only land access to the rest of Europe.
Also Read
The small land border between Gibraltar and Spain has long been a source of tension.
Spain's conservative government in July 2013 imposed for several weeks stringent controls at its border with Gibraltar leading to lengthy queues for motorists, in what it said was a move aimed at clamping down on cigarette smuggling.
But Gibraltar said the stepped-up border controls were in retaliation for the installation of an artificial reef in its waters that has prevented Spanish boats from fishing there.
With Britain out of the EU, the Gibraltar's border would become an external and not an internal EU frontier which has to be kept open under EU rules.
Spain could close the border and a legal challenge by Britain and Gibraltar would be more difficult.