LONDON -- The race to become Britain's next prime minister took a dramatic and surprising turn Thursday, with former London Mayor Boris Johnson -- popular with the public and widely considered a front-runner -- ruling himself out of the race after the defection of a key ally.

In a morning of political machinations and mutterings of treachery that had commentators reaching for Shakespearean parallels, Justice Secretary Michael Gove abruptly withdrew his support for Johnson and announced he was running for the Conservative Party leadership himself.

Johnson, a prominent campaigner for British withdrawal from the European Union, or Brexit, told a news conference that the next Conservative leader would need to unite the party and ensure Britain's standing in the world.

"Having consulted colleagues and in view of the circumstances in Parliament, I have concluded that person cannot be me," he said, to the astonishment of journalists and supporters in the room.

British Lord Chancellor and Justice Secretary Michael Gove arrives for a cabinet meeting at Downing Street, June 27, 2016 in London, England. Jeff J Mitchell, Getty Images

Johnson dropped out after Gove, Johnson's ally in leading the EU "leave" campaign, startled the political world by announcing that he was running to succeed Prime Minister David Cameron.

Get Breaking News Delivered to Your Inbox

The announcement by Johnson, 52, is an astonishing twist in a political career that saw him serve as lawmaker and mayor, building a public profile built on Latin quips and rumpled eccentricity, while nurturing a poorly concealed ambition to lead his country.

Johnson's decision to break with longtime ally Cameron and back the "leave" side in Britain's referendum seemed to have paid off last week, when Cameron resigned after voters decided by 52 to 48 percent to exit the bloc.

Home Secretary Theresa May, Work and Pensions Secretary Stephen Crabb, Energy Minister Andrea Leadsom and former Defense Secretary Liam Fox are also in the race.

British Home Secretary Theresa May launches her bid for the Conservative Party leadership, June 30, 2016, in London,England. Getty

Conservative lawmakers will choose two finalists, and party members will choose they winner by a postal ballot.

The winner of the contest, to be announced Sept. 9, will become prime minister and play a vital role shaping the nature of Britain's relationship with the European Union after last week's Brexit vote ended the career of Cameron, whose bid to keep Britain in the EU block failed.

The bookies' early favorite is May, who is seen by many in the party as a safe pair of hands as the country struggles to disentangle itself from the EU.

"This is not a normal leadership held under normal circumstances," May said in a speech Thursday in London. "The result means we face a period of uncertainty we need to address head on."

Although May had offered a tepid endorsement of Britain's place in the European Union during the referendum campaign, she was clear that the vote would be respected.

"The United Kingdom will leave the EU," she said, pledging to create a brand new government department devoted to negotiating Britain's "sensible and orderly" departure from the 28-nation bloc.

Boosting May's chances was a last-minute falling out between her two leading competitors -- Gove and Johnson -- who had campaigned together to yank Britain from the EU.

Widely liked in the party but less popular with the public, Gove long had disclaimed any ambition to be Britain's leader. In 2012, he said he was willing to "sign a piece of parchment in my own blood saying I don't want to be prime minister." Asked if he would run earlier this month, he said: "Count me out."

In a statement, Gove said he had "wanted to help build a team behind Boris Johnson."

"But I have come, reluctantly, to the conclusion that Boris cannot provide the leadership or build the team for the task ahead," Gove said. "I have, therefore, decided to put my name forward for the leadership.

An email from Gove's wife, Daily Mail columnist Sarah Vine, obtained earlier by Sky News, suggested that Gove should ensure he had specific guarantees from Johnson before backing the latter's bid.

She added that influential right-wing media barons Rupert Murdoch and Paul Dacre "instinctively dislike" Johnson.

Gove's camp has declined to comment on the missive.

The opposition Labour Party is also in extreme disarray, with leader Jeremy Corbyn facing intense pressure to resign after losing a confidence vote. He has lost the support of the party's lawmakers but claims the rank and file still back him.

He is expected to face a formal leadership challenge in the coming days. He has faced heavy criticism for failing to campaign effectively in support of keeping Britain within the EU.