"With such a remarkable shared history, it is inevitable that there are matters on which we have not always seen eye to eye.
"But the strength of our friendship has bred a resilient spirit of cooperation and goodwill," the Queen said at the Buckingham Palace banquet to mark the Spanish royals' state visit.
While her government grapples with Brexit proceedings, the British monarch stressed that "whatever challenges arise" both her country and Spain will prosper.
Guests were served a three-course menu including Scottish beef with bone marrow and truffles, with a Madeira wine sauce.
The glitzy occasion closed the first day of the visit, which saw Felipe raise the issue of Gibraltar in an address to parliament.
"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," he said.
Referring to the history of diplomatic relations between Britain and Spain, he added: "I am certain that this resolve to overcome our differences will be even greater in the case of Gibraltar."
With a population of just over 32,000, Gibraltar has been a British overseas territory since 1713 but Spain has long laid claim to the rocky outcrop.
Unlike Britain, Gibraltar voted overwhelmingly to stay in the European Union in last year's referendum, and it depends on an open border with Spain for its workforce and trade.
But Spain wants shared sovereignty and the EU has promised Spain a veto over the extension to Gibraltar of any future trade deal between Britain and the bloc, prompting outrage in London.
Gibraltar's chief minister Fabian Picardo said that while the population wanted friendly relations with Spain, their position on sovereignty remains clear.
"In the times in which we live, territories cannot be traded from one monarch to another like pawns in a chess game," he said in a statement.
"In Gibraltar the people have spoken loud and clear. Our freely expressed democratic wishes must be respected and that means understanding Gibraltar will remain 100 percent British," Picardo added.
Brexit 'saddens' Spain
Anticipating the tone adopted later by his host, the king's speech was overwhelmingly conciliatory, speaking about shared history between the two countries as well as joint efforts against terrorism after four attacks in Britain this year.
He said Brexit "saddens" Spain but that it fully respected the result of last year's vote.
Felipe spoke about the hundreds of thousands of Spaniards living in Britain and Britons living in Spain, whose future hangs in the balance.
"These citizens have a legitimate expectation of decent and stable living conditions for themselves and for their families," he said, calling for a Brexit deal that would provide "sufficient assurance".
There are an estimated 300,000 British citizens living in Spain -- the majority are retirees -- and around 116,000 Spaniards living in Britain.
The king also expressed sympathy over the recent terror attacks in Britain.
A Spaniard was among eight people killed in an attack by three Islamist sympathisers wielding knives and wearing fake suicide vests in the London Bridge area last month.
Felipe paid tribute to 39-year-old Ignacio Echeverria, who reportedly struck one of the attackers with his skateboard before being stabbed.
The king said Echeverria behaved in "an exemplary and heroic manner".
The visit by Felipe and his wife Queen Letizia was delayed twice, once while Spanish politicians formed a new government last year and again in June because Britain held a snap general election.
The Spanish royals were greeted earlier on Wednesday by the British monarch -- a distant cousin of Felipe -- at an elaborate ceremony in central London.
Felipe will meet British Prime Minister Theresa May on Thursday where the subject of Gibraltar could be raised again.
Business will also be on the agenda, with Spanish executives from Ferrovial, a Heathrow airport shareholder, Santander Bank and telecoms firm Telefonica accompanying the royals.
By Alfons Luna / AFP
- In pics: Spanish royals on parade in state visit to London
- Spain's King and Queen start state visit to UK amid Brexit tensions