By Kylie MacLellan and Elizabeth Piper

LONDON (Reuters) - Former London mayor Boris Johnson abruptly pulled out of the race to become Britain's prime minister that he was once favored to win, upending the contest less than a week after he led a campaign to take the country out of the EU.

Johnson's announcement, to audible gasps from a roomful of journalists and supporters on Thursday, was the biggest political surprise since Prime Minister David Cameron quit after losing last week's referendum on British membership of the bloc.

It makes interior minister Theresa May, a party stalwart who backed remaining in the European Union, the new favorite to succeed Cameron.

May, seen as a steady hand, announced her own candidacy earlier on Thursday, promising to deliver the withdrawal from the EU voters had demanded despite having campaigned for the other side.

"Brexit means Brexit," she told a news conference. "The campaign was fought, the vote was held, turnout was high and the public gave their verdict. There must be no attempts to remain inside the EU, no attempts to rejoin it through the back door and no second referendum."

The decision to quit the EU has cost Britain its top credit rating, pushed the pound to its lowest level against the dollar since the mid-1980s and wiped a record $3 trillion off global shares. EU leaders are scrambling to prevent further unraveling of a bloc that helped guarantee peace in post-war Europe.

The International Monetary Fund indicated that uncertainty over Brexit would hurt economic growth in Britain, the rest of Europe and the wider world. The governor of the Bank of England, Mark Carney, said monetary policy would probably be eased over the summer.

'PUNCHLINE'

Johnson, whose backing for the Leave cause was seen as essential to its victory, saw his leadership bid suddenly crumble after his Brexit campaign ally, Justice Secretary Michael Gove, withdrew support and announced a bid of his own.

"I must tell you, my friends, you who have waited faithfully for the punchline of this speech, that having consulted colleagues and in view of the circumstances in parliament, I have concluded that person cannot be me," Johnson said at the close of his speech at a London luxury hotel.

Supporters, gathered for what they thought would be the first speech of his leadership campaign, were stunned. Johnson began by hailing a "moment for hope and ambition for Britain, a time not to fight against the tide of history but to take that tide at the flood and sail on to fortune".

But by the time he spoke his bid had already been undermined by Gove, a close friend of Cameron's despite differences with the prime minister over Europe, who had previously said he would back Johnson.

In an article on Thursday in the Spectator, a magazine Johnson used to edit, Gove wrote that he had come "reluctantly, to the conclusion that Boris cannot provide the leadership or build the team for the task ahead".

The main opposition Labour Party also faces an acrimonious leadership battle, with lawmakers having overwhelmingly voted to withdraw confidence in left-wing party leader Jeremy Corbyn. Corbyn's party critics say his campaign to remain in the EU was half-hearted. He has refused to go, saying he was chosen by grassroots activists not politicians.

The vacuum at the top of both major parties has added to the uncertainty at a time when Britain faces its biggest constitutional change since the dissolution of its empire in the decades after World War Two.

'DIES BY THE SWORD'

Conservative lawmakers said Johnson may have been undone by supporters of Cameron exacting revenge for his decision to defy the prime minister and back the Leave campaign.

"He who lives by the sword, dies by the sword," said one lawmaker, describing internal party conflict on condition of anonymity. The lawmaker told Reuters Johnson had realized his bid would fail after lawmakers defected from his campaign overnight.

Johnson is the latest political casualty of a civil war in the ruling party unleashed by Cameron's decision to hold the referendum on membership in the EU, an issue that divided the Conservatives for decades and now divides the country.

Known for a jokey public persona and mop of unkempt blonde hair, Johnson became a popular national figure during eight years as London mayor, and used his charm to aid the Leave cause after deciding only late in the day to push for Brexit.

But in the week since his side won, several leading Conservatives questioned whether Johnson had the gravitas to run tough talks to mend the broken relationship with the EU.

In an article in the Times newspaper, May took aim at Johnson's persona by saying government was not "a game".

Britain's new prime minister faces a huge task to unite the party and country, and persuade the EU to offer a deal balancing the desire expressed by voters to reduce immigration with London's aim of maintaining access to EU markets.

A new British leader will also need to reassure financial markets, which have plummeted since the referendum. The pound <GBP=D4> briefly rose after Johnson's announcement.

"The market reaction was that it makes Theresa May a shoo-in, which is less confrontational, less damaging," said Marc Ostwald, strategist at ADM Investor Services.

But some Conservative lawmakers said it was too early to crown May. Conservative members of parliament will first narrow a field of five candidates down to two, and then party members will elect the leader by Sept. 9.

POLITICAL VACUUM

In addition to May and Gove, the candidates are Stephen Crabb, the cabinet minister responsible for pensions, who campaigned to stay in the EU, and two pro-Brexit figures, Liam Fox, a right-wing former defense secretary, and Andrea Leadsom, a minister in the energy department.

Leadsom suggested the next prime minister should come from the Brexit camp. Crabb, who like May has vowed to carry out Brexit despite having opposed it, has said control over immigration should be a red line in talks with the EU.

Scottish leader Nicola Sturgeon blamed the Conservative government for recklessly holding the referendum "purely for internal leadership purposes".

Scots voted by a margin of nearly two to one to stay in the EU, and Sturgeon has said they must not be dragged out against their will, raising the prospect that the United Kingdom itself could break apart.

"Each and every one of you should be deeply, deeply ashamed of yourselves," Sturgeon said to Conservative lawmakers in the Scottish parliament.

(additional reporting by Liz O'Leary in Edinburgh, Andy Bruce, Michael Holden, Paul Sandle, Estelle Shirbon, William Schomberg and Guy Faulconbridge in London; editing by Peter Graff)