It's often said that David Cameron is a lucky politician who has seemed to coast through politics on instinct and charm during a career that has culminated in six years as British prime minister. But now his luck may be running out.

In calling a referendum on Britain's membership in the European Union, Cameron has made a gamble that could end his career — and take his country out of an international alliance it joined more than 40 years ago.

It would be a rare but fateful miscalculation for a politician who has a reputation for thriving under pressure and astutely judging political risks.

"I think he's actually been pretty stunned by the strength of the 'leave' cause," said Cameron biographer James Hanning. "The golden rule is, never hold a referendum unless you're confident of winning it, and I think he thought that the moderate voices would prevail by some distance. But that's not the way the polls are suggesting it's going to go."

The referendum campaign has been unexpectedly bitter and divisive, and was brought to a shocked halt when Labour lawmaker Jo Cox was shot and stabbed to death in the street last week by a man witnesses heard yell "Britain first."

Both sides suspended campaigning out of respect for Cox, amid fears that the political fury unleashed by the EU campaign was somehow connected to the killing.

Before Cox died, opinion polls had shown surging sentiment in favor of a British exit from the 28-nation EU — known as Brexit. A majority of supporters of Cameron's Conservative Party said they would vote to quit the bloc in Thursday's referendum.

That's bitter news for Cameron, who called the referendum to puncture growing support for the anti-EU U.K. Independence Party and placate the strongly Euroskeptic right wing of the Conservatives.

Victoria Honeyman, a lecturer in British politics at the University of Leeds, said Cameron had seen EU battles poison the leaderships of former Tory leaders John Major and William Hague and "feared a civil war in the Conservative Party."

She said the referendum was about "defusing that time bomb" — but Cameron has "moved from having one ticking time bomb to having another ticking time bomb."

When he promised the referendum, in 2013, Cameron said it would "settle this European question in British politics" once and for all.

He told voters he would forge a new deal between Britain and the EU that would make remaining an attractive prospect. At a Brussels summit in February, he won changes to welfare benefits that he said would reduce immigration and an exemption for Britain from the EU's commitment to "ever-closer union" — a phrase that stirs images of a European super-state in some patriotic British hearts.

But many voters have proved resistant to Cameron's message that Britain is stronger, safer and more economically secure within the EU than it would be outside it.

The concessions he gained have been dismissed as paltry by "leave" campaigners, who say they will do little to limit immigration from other EU nations because the bloc guarantees free movement among member states. It's a subject that resonates with many voters, who have seen hundreds of thousands of people come to Britain over the past decade from new EU members in eastern Europe. (Hundreds of thousands of Britons also live in other EU countries, a less remarked-upon fact).

"I think he has underestimated the enduring nature and the strength of the Euroskeptic support in the country and also the extent of the bitterness inside his own party," Hanning said.

Far from healing Conservative divisions over Europe, the referendum has exacerbated them. Cameron has led the "remain" campaign, but let Euroskeptic members of his Cabinet call for a "leave" vote. As a result, senior Conservatives, including former London Mayor Boris Johnson and Justice Secretary Michael Gove, have spent months attacking him.

Tory leader for a decade and prime minister since 2010, Cameron has vowed to stay in office if there is a "leave" vote.

"Will I carry on as prime minister? Yes," he told the BBC last week, vowing to "construct a government that includes all of the talents of the Conservative Party." But many feel he will have little choice but to resign quickly, with a pro-Brexit figure like Johnson or Gove his likely successor.

Even if Britain votes to remain, Cameron's days as leader are numbered. He has already announced he will step down before the next election in 2020. A deeply divided party will likely want him to leave long before that, so that a new leader can help heal the referendum's wounds, and dissident Conservative lawmakers could trigger a no-confidence vote to oust Cameron.

Hanning said 50-year-old Cameron will be worried about what the referendum means for his legacy. A son of privilege, educated at elite Eton College and Oxford University, he has a strong sense of national duty. He won two elections espousing a fiscally conservative, socially moderate "one-nation Conservatism" that he believes speaks to a large swath of the British public.

Tim Bale, professor of politics at Queen Mary, University of London, said Cameron had hoped to be remembered for restoring the economy after the 2008 financial crisis and for social reforms such as legalizing same-sex marriage.

"I think gay marriage will still be an important one," Bale said. "But unfortunately I think he's going to be remembered in the history books as the prime minister who took us out of Europe."

Hanning said Cameron would find that "mortifying." But he said a vote for Brexit would overshadow Cameron's other achievements, just as the decision to join the U.S.-led invasion of Iraq in 2003 has clouded the legacy of former Prime Minister Tony Blair.

"You might say that is his Iraq," Hanning said. "Blair had foreign affairs successes in Northern Ireland, Sierra Leone, Kosovo — and then Iraq was the manifestation of his overconfidence. I suppose people might say this is Cameron's."

___

Follow Jill Lawless on Twitter at http://Twitter.com/JillLawless