LONDON — The last time a terrorist attack erupted on London Bridge in the final weeks of an election campaign, in 2017, the backlash stung the Conservative prime minister, Theresa May, exposing her to a damaging critique by the Labour Party that she had cut funding for the police and left the British people unprotected.
This time, after a lone extremist fatally stabbed two people on Friday before being killed by the police on the bridge, the fallout seemed less likely to alter the course of the election, which is set for Dec. 12. Neither the Conservative Party nor Labour has an especially strong cudgel to wield against the other as the circumstances that put the assailant, a convicted terrorist, back on the streets are complex and involve both parties.
But for Prime Minister Boris Johnson, a potential change agent is still to come — in the form of President Trump, who landed in London late on Monday night to attend a meeting of NATO leaders.
Mr. Trump has roiled British politics on previous visits with inflammatory statements on terrorism, as well as Brexit, trade and other sensitive issues. He is a wild card who could jolt the election with a single tweet.
There is little Mr. Johnson can do to control the president. But he moved quickly to inoculate himself from blame for the terrorist attack.
Mr. Johnson pointed out that the attacker, Usman Khan, had been released early from prison under a law passed, as he put it, by the “leftie government” that preceded a decade of Conservative-led governments.
The truth was far more complicated. Even Mr. Johnson’s senior aides acknowledged that his government would struggle to fulfill the prime minister’s promise, in a column he wrote for the Daily Mail on Saturday, that “these criminals must serve every day of their sentence, with no exceptions.”
Mr. Johnson’s lock-’em-up sloganeering was undermined not only by the two victims of the attack, who were both devoted to prisoner rehabilitation, but also by some of those who disarmed Mr. Khan, themselves ex-convicts or prisoners on day release attending the same conference as he was.
Three of the people who intervened to stop the attack had been locked up at Grendon, a prison focused on group therapy and one of the most progressive facilities in Europe. That suggested to some former prison officials and analysts that the answer is not longer sentences, but rather more useful and therapeutic ones.
“It’s a tale of two prisoners, and two different regimes,” said David Wilson, an emeritus professor of criminology at Birmingham City University and chairman of the Friends of Grendon charity.
“One would hope the message is that people can change — and change not through an off-the-shelf, one-size-fits all kickbox course — but change as a consequence of well-funded, well-staffed rigorous interventions such as those that happen at Grendon,” Mr. Wilson said.
Mr. Johnson has cast himself as the perfect candidate to crack down on ex-convicts, saying he has been pushing for months to end a policy of automatically granting early release to some prisoners, like Mr. Khan.
But the prime minister has struggled to make his case. For one thing, legal experts noted that no proposals of the sort had been in the Conservatives’ manifesto or in recent counterterrorism legislation.
For another, former prison officials and critics said the Conservatives’ own decade-long policy of austerity, including deep cuts to prison and probation service staffing, had sown the seeds of broader threats to public safety.
“We’ve neglected the criminal justice system, and now the chickens are coming home to roost,” Nick Hardwick, a former chairman of the parole board, said in a radio interview on Monday.
Some legal experts also feared that Mr. Johnson would perpetuate a cycle of toughening sentencing laws, only for the government soon to be overwhelmed by a swelling prison population.
The policy that provoked Mr. Johnson’s ire — some prisoners automatically being released halfway into their sentences — was intended to control a booming prison population.
Mr. Khan originally received an open-ended sentence for a terrorism-related offense. But those kinds of sentences were abolished because they left many people languishing in prison for relatively minor offenses.
That did not affect the release of Mr. Khan, who had his sentence reduced separately by an appeals court.
“It’s a good illustration of what happens when you try to throw the net so wide that you effectively lock up hundreds of people on the understanding that maybe there’s a handful of them who might do awful or unpleasant things if they’re not contained,” said Richard Garside, the director of the Centre for Crime and Justice Studies.
Questions about sentencing policy — let alone the rehabilitation and recidivism of people, like Mr. Khan, who have been radicalized — are extremely complex. That does not play to Mr. Johnson’s advantage, given his inattention to detail and reputation for playing loose with the facts.
Jeremy Corbyn, the leader of the Labour Party, faces his own challenges with this issue. He acknowledged on Sunday that he does not believe all people convicted of terrorism should “necessarily” serve their entire sentence.
“I think it depends on the circumstances and it depends on the sentence but crucially depends on what they’ve done in prison,” Mr. Corbyn said to Sophy Ridge of Sky News.
Conservatives seemed likely to seize on his remarks to confirm the suspicion that Labour is soft on crime. As a practical matter, though, their proposals for sentencing in terrorism cases may not be all that different.
The Conservatives have held a steady lead over Labour throughout the campaign. But in recent polls, the gap between them has shrunk to fewer than 10 percentage points, making subtle shifts in the election narrative significant.
The terrorist attack has complicated what the Conservative Party hoped would be a week devoted to security issues — an area in which the Tories historically have an advantage over the Labour Party.
Mr. Johnson, experts said, could play a statesman’s role at the NATO meeting, since he is not as divisive a figure as Mr. Trump or two other leaders: President Emmanuel Macron of France, who recently referred to the alliance as being in state of “brain death,” and President Recep Tayyip Erdogan of Turkey, who antagonized NATO members by sending troops into Syria and buying an advanced air defense system from Russia.
The trouble is that Mr. Johnson’s close ties to Mr. Trump are a liability in an election. With Mr. Corbyn seeking to lash the two men together, Mr. Johnson has avoided having a one-on-one meeting with the president.
“It’s a point of weakness for Boris Johnson to be seen as too close to Donald Trump,” said Malcolm Chalmers, deputy director general of RUSI, a military research center. “The last thing the government wants is for Donald Trump to urge people to vote for his two best friends, Boris Johnson and Nigel Farage,” he said, referring to the leader of the Brexit Party.