LONDON (Reuters) - Spain’s King Felipe said on Wednesday he was confident that an acceptable arrangement could be worked out with Britain over the future of Gibraltar, a British territory that Spain wants back.

Slideshow ( 12 images )

The future of Gibraltar, a rocky enclave on the southern tip of Spain captured by Britain in 1704, and its 30,000 inhabitants is set to be a major point of contention in Brexit negotiations.

Addressing members of both houses of parliament during the first Spanish state visit to Britain in 31 years, Felipe said both countries had overcome “estrangements, rivalries and disputes” in the past.

“I am certain this resolve to overcome our differences will be even greater in the case of Gibraltar, and I am confident that through the necessary dialogue and effort, our two governments will be able to work toward arrangements that are acceptable to all involved,” he said.

The EU annoyed Britain and Gibraltar in April by suggesting Spain has a right of veto over the territory’s post-Brexit relationship with the bloc.

Gibraltar voted strongly in favor of remaining in the EU at last year’s Brexit referendum but remains committed to staying part of Britain and has said it is preparing to lose its preferential access to the EU markets.

The subject is likely to come up when Felipe, who used a speech to the United Nations last year to invite Britain “to end the colonial anachronism of Gibraltar”, holds a bilateral meeting with Prime Minister Theresa May on Thursday.

The pair, who will meet at May’s Downing Street residence on the second day of the three-day, pomp-laden state visit, are also likely to discuss the issue of EU citizen’s rights post-Brexit.

The EU and Britain have yet to agree on guarantees for EU citizens living in Britain and British expats living in other EU countries. More than 300,000 Britons live in Spain, while more than 130,000 Spaniards live in Britain.

Felipe told members of parliament on these citizens had “a legitimate expectation of decent and stable living conditions”.

“I therefore urge our two governments to continue working to ensure that the agreement on the UK’s withdrawal from the EU provides sufficient assurance and certainty,” he said.