(CN) — British Prime Minister Boris Johnson, the colorful but abrasive mop-haired Conservative leader who led the United Kingdom out of the European Union, was forced to announce his resignation Thursday amid scandal and discord.

Johnson is stepping down after months of scandals involving Downing Street parties during coronavirus lockdowns and recent allegations that he promoted a top aide even though Johnson knew he was accused of sexual assault.

Despite a massive revolt by top Conservative members and demands that he step down immediately, Johnson was fighting to stay on for as long as possible and salvage his reputation before leaving office.

In a statement outside Downing Street, Johnson said he was “sad to be giving up the best job in the world” but that in politics “no one is remotely indispensable.”

“But as we’ve seen, at Westminster the herd instinct is powerful, when the herd moves, it moves,” he said in a jab against the more than 50 members of Parliament who resigned from his government in the past two days.

He vowed to remain prime minister until a new Conservative leader is elected, a process that could take months. But many fellow Tories demanded he quit immediately.

Johnson was frantically appointing new Cabinet members to keep his government afloat amid the series of resignations of top Cabinet members and ministers that began Tuesday this week.

A fierce leadership battle is beginning among Tories eager to replace Johnson as prime minister. Johnson led the Conservatives to a resounding election victory in December 2019, but the party is now slumping in polls and suffered humiliating election losses recently.

Johnson’s successor is set to inherit a Tory party in tatters and massive problems, including soaring inflation, a new attempt by Scotland to break away from the U.K., Britain’s deep involvement in the Ukraine war and a potential trade war with the EU over disagreements about the status of Northern Ireland.

The prime minister’s downfall this week began with the resignations of Treasury chief Rishi Sunak and Health Secretary Sajid Javid within minutes of each other Tuesday.

The final straw for Sunak and Javid was the prime minister’s shifting explanations about his handling of sexual misconduct allegations against Chris Pincher, a senior Conservative lawmaker.

Last week, Pincher resigned as Conservative deputy chief whip after complaints emerged that he groped two men at a private club.

More reports about past allegations were lodged against Pincher and questions arose about how much Johnson knew about those accusations when he appointed Pincher as deputy chief whip. As in the U.S. Congress, whips enforce discipline within British political parties.

Johnson’s office initially said he wasn’t aware of the previous accusations when he promoted Pincher in February. By Monday, a spokesman said Johnson did know of the allegations, but that they were “either resolved or did not progress to a formal complaint.”

When a former top civil servant in the Foreign Office contradicted that, saying Johnson was briefed about a 2019 allegation that resulted in a formal complaint, Johnson’s office said the prime minister had forgotten about the briefing, according to the Associated Press.

It was all too much for Sunak and Javid who had been sent onto radio and TV to defend the government’s position, only to find it change.