President Obama and first lady Michelle Obama talk to Britain's Prince William and Catherine, Duchess of Cambridge at Buckingham Palace Tuesday.REUTERS

LONDON — President Obama and First Lady Michelle Obama attended a state banquet Tuesday at Buckingham Palace, where the president described Queen Elizabeth II as a “chief source” of the resilience of the alliance between the United States and United Kingdom.

“This dinner is a humble reminder of the fleeting nature of presidencies and prime ministerships,” Obama said in his toast to the queen. “Your majesty’s reign has spanned about a dozen of each — and counting. That makes you both a living witness to the power of our alliance and a chief source of its resilience.”

Obama thanked the UK for the “solidarity” it has shown since the 9/11 attacks and spoke of the “heavy sacrifices” endured by British troops who are working to prevent “terrorist attacks and violent extremism around the world.”

An awkward moment occurred when the British national anthem began playing during the middle of Obama’s toast. The president hesitantly finished it before clinking glasses with the queen at the anthem’s conclusion.

In her toast, the queen had referenced Obama’s inaugural address, saying he spoke of “the values that lay at the heart of your nation’s success: honesty and hard work, courage and fair play, tolerance and curiosity, loyalty and patriotism.”

“If I may say so, these values underscore much of the life of the United Kingdom, also,” the queen said. “Together with our alliance, they continue to guide our actions as we confront the challenges of a changing world.”

Guests at the dinner included actor Tom Hanks and his wife, actress Rita Wilson, stage and television actress Kristin Chenoweth, director Tim Burton, actress Helena Bonham Carter and actor Kevin Spacey, who was named an honorary Commander of the Order of the British Empire in November for his work as artistic director at London’s Old Vic theater.

Earlier Tuesday, the Obamas were welcomed to Buckingham Palace by the queen. The Obamas, who also met with the newly married Duke and Duchess of Cambridge, were greeted by the monarch and the Duke of Edinburgh after their motorcade swept past cheering crowds outside the palace in central London.

After greeting the royal household, including Prince Charles and the Duchess of Cornwall, the queen showed the Obamas around the six-room Belgian suite where they will stay for two nights.

The group then walked to the gardens, where members of the Scots Guards clad in ceremonial dress and armed with swords stood at the ready. A military band played “The Star-Spangled Banner” and “God Save the Queen,” while a 41-gun salute boomed out across the city.

The president and Prince Philip inspected a Guard of Honor, while the queen and the first lady, who was dressed in a light blue patterned dress and a pink shrug, stood on the terrace in sunny — if blustery — conditions.

At Buckingham Palace, the Obamas also exchanged several gifts with the royal family.

The White House said the president and the first lady gave the queen a collection of rare memorabilia and photographs in a handmade leather-bound album. The collection chronologically highlights the visit of King George VI to the US in 1939.

Prince Philip received a custom-made set of Fell Pony bits and shanks, as well as original horseshoes worn by a recently retired champion carriage horse.

The Obamas gave Prince Charles and the Duchess of Cornwall a selection of plants, seedlings and seeds, as well as jars of honey from the White House beehive.

They also donated six MacBook notebook computers to the Northern Ireland chapter of PeacePlayers International, a global nonprofit organization founded by two American brothers. The charity is one of several selected by the Duke and Duchess of Cambridge to receive donations in honor of their wedding.

Buckingham Palace said the Obamas were given “a selection of [facsimile] letters taken from the royal archives to and from a number of Presidents to Queen Victoria.” The first lady received an antique broach made of gold and red coral.

The Obamas, who arrived in London ahead of schedule on Monday night from Ireland due to concerns over volcanic ash, had lunch at the palace, before viewing the royal picture gallery.

In the afternoon, Obama laid a wreath at the Tomb of the Unknown Warrior at Westminster Abbey. Perhaps suffering from jet lag, the president mistakenly signed the Westminster Abbey guestbook with his name and the wrong date — May 24, 2008.

Obama then met with British Prime Minister David Cameron at Downing Street. Following their meeting, Obama and Cameron made a surprise visit to the Globe Academy, where they played ping-pong with students.

White House deputy national security adviser Ben Rhodes told reporters that Obama “very much wanted to have the opportunity within the context of the formal state visit to get out and interact with some young people.”

Obama also met with Ed Miliband, leader of the opposition Labour Party, for talks that were described as “warm and friendly.” The leaders discussed the challenges facing progressive parties on both sides of the Atlantic, Sky News reported. Miliband gave the president a London 2012 Olympics basketball emblazoned with the British flag, and the first lady received a cookbook by British chef Jamie Oliver.

On Wednesday, Obama will hold talks with Cameron, expected to focus on the Middle East and “Arab Spring,” and will address lawmakers.

Obama was given a hero’s welcome in Ireland on Monday, where he visited the village of Moneygall, the former home of his maternal great-great-great grandfather. The president is due to travel to France on Thursday morning to attend the G-8 summit in the northern resort town of Deauville. The final stop on the trip is Poland.