When Vice President Kamala Harris said last week in Chicago, “you can always trust me to put country above party,” it struck a familiar note in Britain, where the new prime minister, Keir Starmer, used much the same phrase throughout the Labour Party’s relentless march to power earlier this summer.

It’s not the only parallel between Mr. Starmer and Ms. Harris, the Democratic presidential nominee. Both have shaken off or soft-pedaled some of their earlier positions as they try to broaden their party’s appeal. Both are former public prosecutors, who declare a ringing commitment to the rule of law. Both are operating in a volatile environment, where law and order is threatened by extremist elements.

In Mr. Starmer’s case, he was hit with anti-immigrant riots only weeks after his victory, after a deadly knife attack on a children’s dance class was followed by false claims, amplified by people on the far right, that the assailant was a Muslim asylum seeker. (The attacker was born in Britain, police said, and his parents were Rwandan Christians.) In Ms. Harris’s case, some analysts believe she could face unrest if she defeats former President Donald J. Trump in a close race and Mr. Trump or his supporters reject the results.

“These are different countries with different political systems, but there often seem to be parallels in their political trajectories,” said Steven Fielding, an emeritus professor of political history at the University of Nottingham.

Labour and the Democratic Party have long shared tips and swapped strategies, most vividly during the era of Bill Clinton and Tony Blair. So it was little surprise that key members of Mr. Starmer’s political brain trust were in demand at the Democratic National Convention to offer lessons from Labour’s recent victory.