LONDON — Britain’s suddenly unpredictable election campaign moved to the ballot box Thursday as voting began in a race that Prime Minister Theresa May once had solidly in her grip but then reshaped by terrorists attacks in London and Manchester.

May called the snap election seeking to increase her political power ahead of Britain’s exit negotiations with the European Union, pitching herself as the best leader to enter into complex divorce talks.

But the contest shifted in ways no one could have predicted. In a matter of weeks, her far-left opponent, Jeremy Corbyn, has surged as security issues overshadowed the Brexit talks.

As the campaign wrapped up, May’s seemingly insurmountable lead had dwindled to — in at least some polls — to a few points.

May was still expected to pull it out. But if the Labour Party takes control of parliament — and hands Corbyn the keys to 10 Downing Street — it would rival, and perhaps top, 2016’s Brexit vote or President Trump’s November victory for most implausible political outcome of the past 12 months.

Results are expected late Thursday.

May’s pitch won over Miranda John, a 52-year-old mortgage broker who lives in south London and was one of the first to vote after polls opened at 7 a.m. John said she voted for May’s Conservative Party “because of fears of Brexit” and her belief that the Tories have “a better negotiation team.”

“I was a Remainer,” she said, referring to the E.U. referendum held last June. “But I accept that the will is to leave so we need to get the right deal.”

Corbyn has run a “fantastic campaign,” said Henry Wynn, 72, a professor emeritus who described the Labour leader as a “Bernie Sanders socialist” after he voted for Corbyn in the north London neighborhood of Islington.

“I’ll confess,” he added, “we’re in a mildly depressive mood. We face a bleak future with the Tories and I don’t know if we’re going to do it.”

But concerns over how to handle the Brexit talks have been increasingly overshadowed by security worries following two attacks in a span of less than two weeks.

On May 22, a suicide bomber killed 22 people at the conclusion of an Ariana Grande concert in Manchester. In London, eight people died following a van-and-knife rampage around the bustling London Bridge area last Saturday.

May denounced the “tolerance of extremism” that she said persisted in some quarters in Britain — remarks that amounted to an implicit rebuke of Corbyn, who has in the past expressed sympathy for Hamas, Hezbollah and the Irish Republican Army.

But Corbyn quickly pivoted the debate to police cuts that May had authorized during her six-year tenure as home secretary, the nation’s top domestic security official.

The prime minister, he said, had tried to protect Britain “on the cheap” — a message that fit with his anti-austerity mantra and that resonated as details emerged of security services’ failures to thwart the plots.

Even a win for May, if it’s insufficiently convincing, could leave her seriously damaged within her own party and hobbled going into all-important negotiations with European leaders that will determine whether the country’s European Union exit is the success she has promised or a grievous mistake.

“She’ll still win the election, but she’ll be weaker for it,” said Steven Fielding, a political-science professor at the University of Nottingham. “Jeremy Corbyn will lose the election, but he’ll be stronger for it.”

The irony of that outcome, if it comes to pass, will be heightened by the fact that May didn’t need to hold the vote in the first place. With another election not due until 2020, May had repeatedly vowed to wait until then to face the voters after coming to power last year via a selection by her fellow Tory lawmakers.

But the temptation of her party’s more than 20-point lead over Corbyn’s Labour Party proved too great, and the normally cautious May gambled in April by calling an early vote.

At the time, the decision was hailed by observers as a masterstroke — one that could grow her slender parliamentary edge into a historically large majority, giving her the sort of one-woman authority that even Thatcher would have envied.

May would need that sort of endorsement, she insisted in her pitch to voters, so she could stand up to her European counterparts with the knowledge that the country was behind her. Only a strong majority, she argued, would give her leverage to drive the best possible bargain for Britain in the contentious talks to come.

Polls showing that voters admired her resolute and no-nonsense persona — she vowed to be a “bloody difficult woman” in the E.U. talks — suggested she would get what she sought.

But as the campaign has worn on, voters appear to be less convinced that they want to hand her such sweeping control.

“Up until the campaign, events had played to her strengths,” said Rosa Prince, author of a biography of May. “But she does have her frailties. And campaigning seems to have brought a lot of those out.”

Among them: a need to micromanage, an inability to be spontaneous and a distinct absence of the common touch. Her campaign has been widely criticized for being stilted and soulless, with May ducking debates and rarely venturing beyond the friendly confines of scripted events with hand-picked Conservative activists.

When she has, it hasn’t gone well. After a nurse told the prime minister about the struggles of going eight years without a raise on BBC’s “Question Time,” May didn’t bother to empathize and instead shot back that there was “no magic money tree.”

Perhaps most damaging for May was the decision to adopt as official Conservative policy a plan to charge senior citizens more for social care. When the measure was derisively dubbed “the dementia tax,” she quickly abandoned it — then denied that her position had changed.

On Wednesday, she was heckled by butchers during a brief visit to London’s Smithfield Market before retreating to the safer confines of a lawn-bowling club in the countryside. There she sipped tea with elderly Tory voters and told reporters, somewhat implausibly, that she had “enjoyed the campaign.”

Corbyn, by contrast, has campaigned as though he has nothing to lose — which in a way is true. His opinion ratings were abysmal going into the election, with not even a majority of Labour’s supporters saying they would prefer him over May as prime minister. Last year, his fellow Labour lawmakers voted overwhelmingly that they lacked confidence in him as party leader.

But Corbyn — for decades a bomb-throwing backbencher known to voters primarily for his vaguely Marxist views and scruffy beige suits — has been getting a second look as he has aggressively taken his underdog case to the public.

In a country where campaigning is traditionally low-key and door-to-door, the Labour leader has turned heads with large, open-air rallies packed with enthusiastic supporters who cheer his call for a “fairer Britain” after years of Tory austerity.

“They underestimated us, didn’t they, seven weeks ago?” he asked one such gathering on the streets of Glasgow. “They underestimated the good sense of ordinary people all over Britain.”

The crowd roared.

“He’s genuinely enjoyed campaigning because there’s no pressure on him,” Fielding said. “There’s a very obvious contrast with May only engaging a small number of Conservative activists at an empty storage facility on the edge of town.”

“One attack is unfortunate,” said Joe Twyman, head of political research for the polling firm YouGov. “Two attacks is: ‘Should we have been doing more? Is the government failing us?’ ”

What’s clear, Twyman said, is that May’s gamble in calling the vote has hardly gone according to plan — and that could hurt her in the long run, even if she wins.

“Questions are being asked about her that weren’t being asked before,” he said. “Her image has taken a hit.”