LONDON — President Trump’s cancellation of a visit to London to open a new United States embassy was welcomed by his many critics in Britain on Friday, even as it deepened the diplomatic problems confronting a British government struggling to forge closer ties to Washington without offending opinion at home.

The decision averted the risk of public protests that had threatened to embarrass both Mr. Trump and Britain’s prime minister, Theresa May, who has recently squirmed to distance herself from statements made by an American president seen by many Britons as deeply divisive.

The announcement, which came in a Twitter post by Mr. Trump that included a false jab at former President Barack Obama, is the latest reverberation from a hasty and ill-judged invitation made around a year ago, when Mr. Trump was offered, and accepted, a state visit to Britain. Such an honor is normally bestowed only much later in a presidency.

With Britain to leave the European Union in 2019, Mrs. May hopes to negotiate a new trade agreement with the United States, and the state visit was partly seen as a way of cementing ties with Mr. Trump.