President Donald Trump has praised the "eternal friendship" between the UK and US as he joined a state banquet at Buckingham Palace.
The Queen said the countries were celebrating an alliance which had ensured the "safety and prosperity of both our peoples for decades".
The president is in the UK for a three-day state visit, which includes the 75th anniversary of the D-Day landings.
Earlier in the day, Mr Trump criticised the mayor of London.
But in his speech at the banquet, Mr Trump praised the courage of the British people during World War Two and called the Queen a "great, great woman".
"In that dark hour, the people of this nation showed the world what it means to be British," he said, adding that their bravery ensured that the destiny of the country "remained in your own hands".
Mr Trump ended his speech with a toast to "the eternal friendship of our people, the vitality of our nations and to the long-cherished and truly remarkable reign of Her Majesty the Queen".
The Queen praised the two countries' role in creating an assembly of international institutions that would ensure "the horrors of conflict would never be repeated".
On Twitter before the banquet, Mr Trump praised the welcome from the Royal Family as "fantastic" and said the relationship with the UK is "very strong".
He also said a post-Brexit trade deal could happen once the UK removed the "shackles", adding: "Already starting to talk!"
Large-scale protests are planned in several UK cities during the three-day visit, including in London, where a "national demonstration" will start at Trafalgar Square at 11:00 on Tuesday.
Labour leader Jeremy Corbyn - who boycotted the state dinner - is due to attend and speak at the London demonstration, a party spokesman has confirmed.
Earlier, Mr Corbyn tweeted: "Tomorrow's protest against Donald Trump's state visit is an opportunity to stand in solidarity with those he's attacked in America, around the world and in our own country - including, just this morning, Sadiq Khan."
Mr Trump's tweet about Mr Khan accused him of doing a "terrible job" as mayor, adding: "[He] has been foolishly "nasty" to the visiting president of the United States, by far the most important ally of the United Kingdom. He is a stone cold loser who should focus on crime in London, not me."
By James Landale, BBC diplomatic correspondent
The contrast could not have been starker. The President of the United States received a warm welcome from the Queen and the Prince of Wales at Buckingham Palace.
There were two 41-gun salutes - one for Mr Trump and another marking the 66th anniversary of the Queen's coronation on Sunday - as well as an honour guard of young Grenadiers resplendent in scarlet.
At the same time, Mr Trump launched a verbal attack on the mayor of the city in which he is now a guest, calling Sadiq Khan "a stone cold loser" for questioning why the president had been granted a state visit.
In truth, this is all of a piece for Mr Trump: he gets the pictures and the pageantry that he wants and will look good in his re-election campaign next year, and he gets to pick a fight with a liberal, Muslim politician that will play well with his base.
Already this row is forcing those campaigning to be Britain's prime minister to define themselves against Mr Trump.
Foreign Secretary Jeremy Hunt criticised Mr Khan for his "great discourtesy". But Health Secretary Matt Hancock said the office of the mayor of London should be respected in the same way one respects the office of the president.
This visit has only just begun and already the Great Disruptor is tweeting angry thoughts and breaching diplomatic niceties. Business as usual, you might think - only today he also happens to be a guest of the Queen, who rarely tweets and is always diplomatic.
A spokesman for Mr Khan said "childish insults" should be beneath the US president, adding: "Sadiq is representing the progressive values of London and our country, warning that Donald Trump is the most egregious example of a growing far-right threat around the globe."
House of Commons Speaker John Bercow and Liberal Democrat leader Sir Vince Cable also boycotted the state banquet.
The Duchess of Sussex did not attend following the birth of her son Archie, who is less than a month old. On Sunday, Mr Trump denied calling the duchess "nasty", despite him using the word on tape.
But the guests included the Duke and Duchess of Cambridge as well as prominent Americans living in Britain.
As he stepped onto UK soil at Stansted Airport, Mr Trump was greeted by US Ambassador to the UK Woody Johnson and Foreign Secretary Jeremy Hunt.
Tory leadership candidate Mr Hunt, who has spoken about the importance of the UK's relationship with the US, said Mr Trump mentioned to him "some of his very strong views about the mayor of London".
Crowds were gathered outside Buckingham Palace as the president and first lady landed by helicopter shortly after midday.
The Queen presented Mr Trump with a first edition of Sir Winston Churchill's book The Second World War, from 1959, with gilt decorations and hand-sewn bindings in the colours of the US flag. He was also given a three-piece Duofold pen set decorated with an EIIR emblem, in a design made exclusively for the monarch.
Mrs Trump received a specially commissioned silver box with a handcrafted enamel lid, decorated in royal blue with roses, thistles and shamrocks to represent the ceiling of Buckingham Palace's music room.
After the private lunch, the Queen showed the couple American artefacts and other items from the Royal Collection. In a nod to the US leader's Scottish heritage, he was shown a bolt of Harris tweed.
Mr and Mrs Trump met the Duke of York at Westminster Abbey, where they laid a wreath at the grave of the unknown warrior.
The president signed the distinguished visitor's book in his customary black marker pen, describing the 13th Century church as a "special place".
Their next stop was Clarence House, where they joined Prince Charles and the Duchess of Cornwall for tea.
Fans and critics outside Buckingham Palace
By Hamish Mackay, BBC News
A quick walk around the crowd outside Buckingham Palace revealed the presence of supporters and detractors of Mr Trump - both equally strong in their views.
Phillip Butah, from Essex, wearing a MAGA hat and describing himself and his companion as "Trump activists", says: "We are so happy that he's here - this visit is long overdue."
Asked what they expect the UK to get from this visit, they reply: "Trade deals."
Corey Wright, a 25-year-old American from Ohio, in London as a tourist, sees the visit in a similar light.
"I think the visit is good for the political environment," he says. "I think that needs to be worked on and that's what he's here to do."
Auriel Granville - a climate activist from Wimbledon, south-west London - came dressed as the Statue of Liberty to protest against the president's visit.
"I don't think he should be received in this way - climate change should be top of our agenda and Donald Trump is a climate change denier," she said.
Talks between Mr Trump and outgoing Prime Minister Theresa May will begin on Tuesday. Although Mr Trump has spoken of his admiration for Mrs May, there are expected to be differences of opinion during their talks.
The prime minister will raise the issue of climate change, with a government spokesman again saying on Monday the UK was "disappointed by the US decision to withdraw from the Paris Agreement in 2017".
The two leaders are also expected to discuss Huawei. The US has blacklisted the Chinese firm for security reasons, while the UK may allow it to supply "non-core" components for its 5G network.
The president's visit coincides with the commemorations for the 75th anniversary of the D-Day landings, which the Queen, Mr Trump and other heads of state will attend at Portsmouth on Wednesday.
Before the visit, President Trump told the Sun newspaper he was backing Conservative Party leadership contender Boris Johnson to be the next UK prime minister.
He also told the Sunday Times that Brexit Party leader Nigel Farage - an arch critic of Mrs May - should be involved in the government's negotiations to leave the EU.
Although the Queen has met 12 of the 13 US presidents who have been in office during her reign, Mr Trump's state visit to the UK is only the third by a US leader.
George W Bush and Barack Obama are the only other US presidents to have been given a state visit.
State visits differ from official visits and are normally at the invitation of the Queen, who acts on advice from the government. The Queen usually receives one or two heads of state per year and has hosted 112 of these visits since becoming monarch in 1952.