The sovereignty of Gibraltar is not up for negotiation, Defence Secretary Geoff Hoon has said during a visit marking 300 years of UK rule there.
Geoff Hoon at Gibraltar celebrations with its governor Sir Richard Francis and chief minister Peter Caruana
But Mr Hoon warned that as the European Union evolves and develops "there may be implications for Gibraltar".
Earlier 12,000 Gibraltar residents formed a human chain around the Rock.
Spain's Prime Minister Jose Luis Zapatero said such celebrations were "inappropriate" but called for calm and cautious "dialogue".
An unofficial referendum in 2002 showed nearly 99% of Gibraltarians were opposed to any idea of joint rule between Britain and Spain.
Later the Royal Navy was handed the Freedom of the City of Gibraltar by the Rock's parliament as part of a string of celebratory events
Madrid wants the Rock returned to Spain but Gibraltarians want to stay British.
Mr Hoon welcomed the demand for a more constructive approach and said he would study any Spanish proposals.
But he added that the Rock's sovereignty "was not on the table".
Spanish foreign secretary Miguel Angel Moratinos said Mr Hoon's decision to attend was "unfriendly" and showed a clear lack of sensitivity by London.
1704 Britain captures Gibraltar from Spain
1713 Spain formally cedes it to Britain
1783 Spain ends four-year siege
1830 Becomes British colony
1967 Residents' referendum rejects Spanish sovereignty
1969 Constitution affirms UK ties but brings self-government
98.97% of Gibraltar's population vote against shared British-Spanish sovereignty
He said nobody could deny Gibraltarians their right to commemorate their history but an exercise of self-restraint might have been expected from the British government.
Mr Moratinos told Spanish newspaper El Pais: "This commemoration of a past military event weakens the relationships with Spain.
"It turns out to be very strange that in this 21st century, the military occupation of part of an EU member-state's territory is commemorated by another member-state."
Downing Street insisted Britain maintained a "good relationship" with the Spanish.
"They are an EU and Nato partner. It would be appropriate for a member of the Cabinet to attend the ceremonies there. I don't think there is any difficulty with that," a spokesman added.
Gibraltar's chief minister Peter Caruana accused the Spanish of being obsessed by Gibraltar and said they had no right to interfere.
He said: "How we choose to celebrate our very close links with Britain and our British sovereignty is a matter for us."
Mr Caruana also criticised the US for withdrawing the naval frigate USS McFaul from the ceremonies in response to pressure from Madrid.
Shadow Foreign Secretary Michael Ancram said he was "disappointed" by the Spanish government's reaction and urged them to be "grown up".
He said it would only increase the resolve of Gibraltarians to remain British.
"It shows the Spanish government does not understand the situation sufficiently to move forward.
"People who live on the Rock made it absolutely clear that they wish to remain British."
Tory MEP for the South West Neil Parish, whose constituency takes in Gibraltar, said it was right the British government were at the events because many Gibraltarians feared a secret deal on the Rock's future had been struck between the two governments.
"We just have to keep up the pressure and say 'Look, the people of Gibraltar have no intention to give up their British sovereignty, and let's grow up and get on with the world as it is and have a better deal and not keep closing the border'," he said.
The tercentenary celebrations began on Saturday with the arrival of HMS Grafton in Gibraltar following a tour of duty in the Persian Gulf.
On Wednesday, Mr Hoon and First Sea Lord Sir Alan West watched a military parade of more than 300 British soldiers.
HMS Grafton, which infuriated Spaniards by firing a 21-gun salute as it sailed into port, is being joined by two Royal Fleet Auxiliary ships.
The Queen's Colours - normally flown only when a member of the Royal Family is present - will be on parade in recognition of the anniversary's importance.
The row is the third time in three months Anglo-Spanish relations have been strained over Gibraltar.
In June there were protests over a visit by Princess Anne and in July a port call by the British nuclear submarine HMS Tireless drew criticism.