The King of Spain has said he is confident his country and Britain can find a solution on Gibraltar "acceptable to all involved".
King Felipe raised the controversial topic as he addressed MPs and peers at the Royal Gallery in the Houses of Parliament, outside which the flag of Gibraltar was on display.
Conservative MPs had threatened to walk out of the speech if the monarch laid claim to the territory during his speech, but his considered remarks did not see this happen.
But Fabian Picardo, the Chief Minister of Gibraltar, gave the comments a guarded response, telling Sky News: "What the king has said really harks back to a time when the governments in Madrid and London might make decisions over the heads of the people of Gibraltar."
King Felipe continued: "It is just as true, however, that during our rich and fruitful history there have also been estrangements, rivalries and disputes, but the work and determination of our governments, authorities and citizens have relegated such events to the past.
"I am certain that 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 towards arrangements that are acceptable to all involved."
The flag's presence was earlier welcomed at Prime Minister's Questions by Conservative MP Andrew Rosindell, who urged Prime Minister Theresa May to remind the King that Gibraltar is British, despite long-standing Spanish claims to the territory.
The Queen and King Felipe ride in a carriage during the monarch's state visit
Flags of the overseas territories and dependencies are regularly raised outside Parliament for state occasions like the King's visit, and Gibraltar's flag is placed in the middle because they are in alphabetical order.
Flags of Commonwealth nations were displayed at Horse Guards Parade.
King Felipe also addressed Brexit during his speech, saying any deal must give the thousands of his compatriots in Britain - and UK expats in Spain - "sufficient assurance and certainty" over their futures.
He said those citizens have a "legitimate expectation of decent and stable living conditions", amid criticism from Brussels of the offer made by Mrs May.
Prince Charles and King Felipe share a laugh during a meeting at Clarence House
King Felipe said Brexit "saddens" Spain but that it "fully respects" the will of the British people.
He continued: "At the bilateral level, our governments must work with determination to maintain and even improve the network of relations we have built within the European project.
"Given these circumstances, we must particularly bear in mind the thousands of Britons and Spaniards who live in each of our nations, who form a sound foundation for our relations.
"Those citizens have a legitimate expectation of decent and stable living conditions, for themselves and their families.
"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."