Three hundred years after the tiny enclave of Gibraltar was handed to Britain by Spain as part of the treaty of Utrecht – the Rock had been occupied nine years before – its possession remains a running sore in relations between London and Madrid.

The evacuation of the civilian population during the second world war and a 16-year border closure between 1969 – 1982 (for pedestrians) and 1985 (for other traffic) were the most serious crises in living memory.

In 1982, Margaret Thatcher also agonised over its vulnerability to attack from Spain during the Falklands conflict – and there have also been disputes over fishing rights.

In the past five decades, whether under the dictatorship of General Franco, who called the Rock a "dagger in the spine of Spain" or the restored parliamentary democracy, Madrid has involved royalty in its battle to regain control.

In 1954, Spain cut air links in protest against a visit to Gibraltar by the Queen. King Juan Carlos boycotted the wedding of Prince Charles and Lady Diana in 1981 over the couple's plans to start their honeymoon from Gibraltar, while last year Queen Sofia made herself absent from a jubilee lunch for the world's monarchs at Windsor.

Diplomatic efforts by Thatcher and Tony Blair to broker proposals for joint sovereignty were repelled in referendums in 1967 and 2002 (by 98.9% of voters in the later poll), while local politicians have encouraged the territory's development as a hub for offshore banking and online gambling.

Over the last decade there had been some co-operation between governments, even as Spain continued its sovereignty claims. In 2006, ministerial delegations from Britain, Gibraltar and Spain signed the Cordobá agreement on joint use of the airport, pension compensation for former Spanish workers on the Rock and upgraded telecoms links.

In July 2009, the then foreign minister, Miguel Ángel Moratinos, became the first Spanish cabinet minister to visit Gibraltar for the first time in more than three centuries.