By Elizabeth Piper

LONDON (Reuters) - It was David Cameron's biggest gamble and he was convinced he would win. Now, the British leader's closest rival – in the EU referendum, in the Conservative Party and in the country – is the frontrunner to take his job.

Britain's decision to leave the European Union, a victory for the populist cause, may be a defining moment for Britain and the European project. On Friday, it sent shares and the sterling currency sharply lower amid warnings of damage to the economy.

The one man to ascend is Boris Johnson, the former London mayor and schoolmate of Cameron's who became the household name of the "Out" campaign even as the prime minister battled for "In".

With Cameron's announcement that he will resign after the British public voted against him, Johnson is now the strongest candidate to replace him.

But the moment of victory is fraught with challenges - first he will have to convince Conservative lawmakers to back him and then persuade the party's largely eurosceptic wider membership, who may challenge what his critics call a record of changing his views to suit his audience.

For Cameron, the turning point came in February when Johnson, a politician who has built a broad appeal beyond the ruling Conservative Party, threw his support behind the "Out" campaign in what several sources say was a calculated move to boost his chances of replacing the prime minister.

Cameron gave in to vocal eurosceptics in his party in early 2013 to put Britain's EU membership to the public vote. It was an attempt to bury the question of Britain's EU membership that has bedevilled successive governments.

Initially, Cameron thought he could woo Johnson to his side. A friend and former colleague of Johnson said the former mayor could have been guaranteed a position in Cameron's cabinet - or group of top ministers - had he agreed to campaign alongside the prime minister.

Instead he lent his support, and with it his broad popularity among voters, to the "Leave" campaign.

"He is such an asset to that campaign, he made it optimistic, energetic and positive," the friend told Reuters.

CAMERON MIS-STEPS

Aides to the prime minister said Cameron believed he could have easily won the fight to keep Britain in the EU if he had had the support of Johnson, who used his position as mayor of London between 2008 and 2016 to broaden his appeal beyond the Conservative Party by supporting gay rights and immigration.

The prime minister already had the weight of expert opinion in big business, entertainment and sport from across the country and beyond. These groups had been carefully polled and aides had held numerous focus groups that indicated that the "out" campaign could win only 42 percent of the vote by arguing solely on immigration.

The aides, and Cameron himself, had campaigned for Johnson's support, but while the prime minister and the former mayor had "always got on pretty well", their's was essentially a political relationship, the friend said.

"They had a relationship when they could afford to be quite ballsy with each other because they were close," the friend said, pointing to their shared background - both were educated at the elite Eton school and knew each other at Oxford University.

Like almost every politician, Johnson is ambitious, the friend said. And if his backing of the "Leave" campaign was not entirely unexpected, it was frustrating, according to a former Cameron aide who also spoke on condition of anonymity.

That frustration boiled over in parliament a day after Johnson declared his hand and criticized the prime minister's new deal with the EU of a "special status" for Britain that Cameron thought should bolster his case for remaining.

After rubbishing a suggestion made by Johnson and others in the "Out" campaign that a vote to leave could prompt a deeper renegotiation of Britain's ties with the block, Cameron said:

"I am not standing for re-election. I have no other agenda than what is best for our country."

His aides deny it was an attack on Johnson, but for dozens of eurosceptic Conservatives and others who were undecided over which way to turn, it seemed to contradict Cameron's pledge to be respectful of those who disagreed with him.

Andrew Bridgen, a senior Conservative lawmaker who campaigned for Britain to leave, described the exchange as akin to a "pub brawl" when "you hit the biggest, most dangerous-looking bloke as hard as you can and hope he doesn't get back up again".

The "Out" campaign, instead, stole the initiative with the beginning of "purdah" - a four week period when the government is banned from making announcements that could sway the vote, he said.

"It's unfortunate that the prime minister and chancellor (finance minister) put themselves at the front and center of the Remain campaign so the collateral political damage is really quite immense," Bridgen said.

He added that when it comes to negotiating Britain's departure from the EU, the talks must be led by one of the leaders of the "Leave" campaign - possibly justice minister Michael Gove, someone Cameron had counted as a close friend according to sources close to the prime minister and leading Conservatives.

EUROPE CURSE

Cameron, who announced his resignation with tears in his eyes outside his residence at 10 Downing Street, will stay on until October, earning a little time to try to smooth the transition in the Conservative Party.

But with his party's right-wing in the ascendance, a new leader is expected to come from the eurosceptic camp, potentially putting paid to secure his legacy as a "moderniser" of the party and his much hoped for succession of George Osborne, the finance minister.

Johnson, whose persona as a 'buffoon' can charm and repel in equal measure, is at the front of the pack.

But his gamble - abandoning his support of immigration to win more support from the Conservative Party which will elect its next leader, and new prime minister - may undermine his wider popularity.

"The only damage could be to his personal integrity and a sacrifice of his appeal beyond the typical Conservative Party member," said a friend.

There was evidence of that difficult road on Friday morning. As Johnson left his north London residence to make his first statement since the referendum result, he was booed and jeered by Londoners who may have once supported him.

(additional reporting by Paul Sandle, William James and Kylie MacLellan, editing by Janet McBride)