President Trump said late Thursday that he had canceled a trip to London because of the cost and “off location” of the new United States Embassy in the city, where he had been expected to face protests.

Nearly a year ago, Mr. Trump accepted an invitation to visit from Queen Elizabeth II, which was extended by Prime Minister Theresa May of Britain while she was in Washington shortly after Mr. Trump’s inauguration.

That announcement set off a year of debate in Britain, where Mr. Trump is unpopular, and the timing of the visit was continually pushed back. British newspapers cited concerns about protests during a visit as officials tried to gauge how much pomp should greet Mr. Trump.

Last month the United States ambassador to Britain, Woody Johnson, said that while no trip had been formally announced, he hoped Mr. Trump would visit in early 2018 and dedicate the new embassy.

On Thursday night, the president took to his favorite medium, Twitter, and announced that he had canceled his trip because he was unhappy with the new building.

The old embassy, in a historic square in the exclusive Mayfair neighborhood, was deemed to be vulnerable to terrorist attacks. The new one is in a former rail yard on the South Bank of the Thames. Mr. Trump blamed the Obama administration for the move, accusing it of selling the old embassy for “peanuts” in a “bad deal.”

But the move was actually initiated during the administration of President George W. Bush. “This has been a long and careful process,” Robert Tuttle, then the ambassador to Britain, said in October 2008.

The Trump presidency has complicated the normally close ties between the United States and Britain, which has often been called the “special relationship” since Winston Churchill used the phrase in a 1946 speech.

Mr. Trump has used terrorist attacks in London to support his travel ban on visitors from predominantly Muslim countries. He criticized London’s mayor, Sadiq Khan, for his response to a bombing in June, misconstruing a call for calm as lack of concern about terrorist threats. And his tweets about a bombing in London in September suggested that the police had been monitoring attackers but done nothing.

His retweets of a far-right group’s anti-Muslim videos from in November triggered criticism from across the political spectrum in Britain.