Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

LONDON — President Donald Trump has canceled a trip to London to open the new U.S. Embassy, blaming the Obama administration for selling the old building in the city for "peanuts."

He criticized the move from "perhaps the best located and finest embassy," even though the relocation was initiated under the George W. Bush administration in 2008 amid wider security concerns after terror attacks such as the 1998 embassy bombings in Tanzania and Kenya.

Trump's decision was greeted with relief by London's Mayor Sadiq Khan, who said the president had "finally got the message" that he was not welcome in the British capital.

The looming trip — and a state visit for which no date has been set — threatened to be a security headache for authorities who feared mass protests.

A recent poll commissioned by The Independent newspaper found 48 percent of British people believe the U.K. should withdraw the invitation for a full state visit, and more than 1.8 million people signed a petition to stop it from going ahead.

An exterior view of the new US Embassy at Nine Elms in London. Andy Rain / EPA file

The new embassy, in a purpose-built site in London's regenerated Nine Elms district, was designed with security in mind.

The existing facility, in Mayfair's Grosvenor Square, is not set back from the road and unsightly barricades were installed around it after 9/11.

Robert Tuttle, then the U.S. ambassador, said of the decision to move: “We realized that the goal of a modern, secure and environmentally sustainable embassy could best be met by constructing a new facility.”

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Nine Elms is slated to become London's new embassy district, but its location south of the River Thames is seen as less fashionable than Mayfair; Trump called the new site an "off location."

He said on Twitter: "Reason I canceled my trip to London is that I am not a big fan of the Obama Administration having sold perhaps the best located and finest embassy in London for 'peanuts,' only to build a new one in an off location for 1.2 billion dollars. Bad deal."

An embassy statement said the cost of the new building had been funded entirely from the proceeds of the sale of other U.S. government properties in London and "not through appropriated funds."

The United States Embassy in Grosvenor Square, central London. Alastair Grant / AP file

In 2015 Lydia Muniz, the director of the bureau of overseas building operations at the State Department, said that upgrading the existing embassy would have cost $550 million and it still would not be as secure as the new site, according to The Associated Press.

The current American ambassador, Robert "Woody" Johnson, said last month that the $1 billion building was designed to be both welcoming and secure and described it as a "bargain."

The old embassy building has been sold to a Qatari-owned development firm that has proposed transforming it into a luxury hotel. Under the plans, the building will be refurbished into a 137-room five-star hotel and spa, featuring five restaurants and six high-end shops.

The value of the deal has not been released but the Canadian High Commission, a much smaller building also on Grosvenor Square, sold in 2013 for almost $500 million, according to the AP.

Many Londoners have made it clear that Donald Trump is not welcome here while he is pursuing such a divisive agenda. It seems he’s finally got that message. pic.twitter.com/YD0ZHuWtr3 — Sadiq Khan (@SadiqKhan) January 12, 2018

Khan said a Trump visit would "without doubt" be met by mass protests. "Many Londoners have made it clear that Donald Trump is not welcome here while he is pursuing such a divisive agenda," the mayor said. "It seems he's finally got the message."

Trump and Khan have clashed before; in the hours after a deadly terrorist attack last year on London Bridge, the president tweeted that the mayor was "pathetic."

Former opposition party leader Ed Miliband said the reason Trump had canceled his trip was "because nobody wanted you to come. And you got the message."

But Britain's Foreign Secretary Boris Johnson defended Trump, saying Khan and opposition Labour party leader Jeremy Corbyn were endangering relations between Washington and London.

Nope it’s because nobody wanted you to come. And you got the message. https://t.co/9xV7bFZQgL — Ed Miliband (@Ed_Miliband) January 12, 2018

"The U.S. is the biggest single investor in the U.K. — yet Khan & Corbyn seem determined to put this crucial relationship at risk," Johnson tweeted. "We will not allow U.S.-U.K. relations to be endangered by some puffed up pompous popinjay in City Hall."

During her visit to Washington a year ago, British Prime Minister Theresa May extended a reciprocal invitation to Trump, but activists immediately threatened to stage protests and lawmakers demanded that he should not be given the opportunity to address Parliament.

Agovernment spokesman told NBC News that “an invitation for a state visit has been extended and accepted and there will be further details in due course.”

More recently there has been speculation that Trump would be invited to Prince Harry's wedding to the American actress Meghan Markle in May, although the prince is actually friends with former President Barack Obama.

The US is the biggest single investor in the UK - yet Khan & Corbyn seem determined to put this crucial relationship at risk. We will not allow US-UK relations to be endangered by some puffed up pompous popinjay in City Hall. — Boris Johnson (@BorisJohnson) January 12, 2018

British-U.S.relations reached a low at the end of last year, after May issued a rare rebuke of Trump for retweeting inflammatory anti-Muslim and anti-immigrant videos originally shared by a far-right U.K. political group.

Phil Helsel reported from Los Angeles, and Saphora Smith from London.