Prime Minister Rishi Sunak of Britain apologized on Friday for leaving early from a D-Day commemoration in France, admitting to a major public relations misstep in the heat of a general election campaign.

“After the conclusion of the British event in Normandy, I returned back to the UK,” Mr. Sunak wrote on the social media platform X. “On reflection, it was a mistake not to stay in France longer — and I apologise.”

Mr. Sunak did not explain why he had decided to leave early. But once back in London, he recorded an interview with the British network ITV, in which he was quizzed about his claim during a televised debate this week that the opposition Labour Party would raise taxes on British households by 2,000 pounds, about $2,560.

Mr. Sunak’s apology came after a storm of criticism, with the election less than four weeks away.

The Labour Party condemned his early departure as a “dereliction of duty.” The leader of the Liberal Democrats, Ed Davey, accused Mr. Sunak of abandoning the aging veterans of the D-Day invasion “on the beaches.” Even some officials of Mr. Sunak’s own Conservative Party expressed dismay.

Mr. Sunak’s departure meant that his foreign secretary, David Cameron, was left to represent Britain at an afternoon ceremony with the leaders of France, Germany and the United States.

That set up an unusual tableau of Mr. Cameron, a former prime minister, posing for photographs on Omaha Beach with President Biden, President Emmanuel Macron of France and Chancellor Olaf Scholz of Germany.