WASHINGTON — The White House announced on Thursday that President Trump will make his first visit to Britain on July 13, a trip the White House had repeatedly put off amid friction between the American president and one of the United States’ closest allies.

Prime Minister Theresa May of Britain was the first foreign leader to visit the White House after Mr. Trump took office, and said then that she had conveyed an invitation from Queen Elizabeth II for Mr. Trump to make a formal state visit to Britain, which the president accepted.

But in the year since, the visit has become more like an on-again, off-again date, with a politically tricky back story to match. The July trip will be a working visit with Mrs. May, according to Sarah Huckabee Sanders, the White House press secretary, a downgrade from the kind of ceremonial state visit that was initially offered.

Mr. Trump had been scheduled to visit London earlier this year to open the new American Embassy but abruptly canceled the trip with a message on Twitter in January in which he blamed the cost and location of the building. Both British and American officials speculated at the time that the president had scrapped the visit because of the risk of public protests that had threatened to embarrass both Mr. Trump and Mrs. May, who was doing her best to distance herself from him after statements Mr. Trump had made that some Britons considered deeply divisive.