WASHINGTON — On one level, President Trump reacted to Saturday night’s terrorist attack in London much as his predecessors might have. He expressed solidarity and telephoned Britain’s prime minister to offer condolences. “WE ARE WITH YOU,” he wrote to Britons.

But even as the investigation into the attack was getting underway, Mr. Trump wasted little time in using the episode to defend his hotly disputed travel ban on visitors from certain predominantly Muslim countries and to criticize the judges who have blocked it. And by Sunday morning, he decided to go after the mayor of London as not being tough enough on terrorism.

Along the way, he mischaracterized the mayor’s position, renewed a trans-Atlantic feud stretching back a year and widened his rift with the United States’ traditional European allies a bit further. And he set off a chain reaction in the news media world, triggering partisan reactions that illustrated just how polarized both the United States and the world have become about the uninhibited, Twitter-obsessed president.