Labour Party leader Ed Miliband is congratulated by supporters in Birmingham, central England. Prime Minister David Cameron’s Conservatives suffered heavy losses in local government elections. (Darren Staples/Reuters)

Britain’s ruling coalition sustained punishing losses in local elections, with final results released Friday showing both the Conservatives and their partner Liberal Democrats giving up hundreds of seats in a stinging rebuke of the two-year-old government of Prime Minister David Cameron.

The results showed the opposition Labor Party gaining 823 seats in Thursday’s vote — and winning control of key cities including Birmingham and Cardiff — in what analysts saw as a protest vote against the Conservatives’ tough austerity drive, the flagging British economy and a series of recent missteps that has left voters questioning the competence of the Cameron government.

The Conservatives, however, won a major consolation prize — the reelection of London’s eccentric mayor, Boris Johnson. The mop-topped Conservative defeated his Labor challenger, Ken Livingstone, who had formerly held the top job in Europe’s largest city. The win further positions the gaffe-prone, blunt-talking Johnson as a potential challenger to Cameron’s leadership of the Conservative Party in the years ahead.

But elsewhere around the country, the results amounted to a major setback for the coalition. A beaming Ed Miliband, head of the Labor Party, traveled to Birmingham on Friday to revel in the opposition’s big night, describing the local elections as a foreshadowing of the national race in 2015, when he will try to take the premiership away from Cameron. Seats on local town and city councils across Britain are considered key to garnering grass-roots votes in national elections.

“The battle to change Britain begins here,” Miliband said.

Voters also showed surprisingly strong support for the right-wing Independence Party, which campaigned on a platform that includes having Britain withdraw from the European Union. The party’s strong showing could amount to a wake-up call for Cameron, seen as a moderate reformer who has attempted to shift the Conservatives closer to the political center. The coalition’s junior partners — the Liberal Democrats — continued a major unwinding of support since their decision to join the Conservatives in government two years ago, with the number of elected local councilors from the party falling to a record low.

Analysts said the bloodbath could have been far worse, pointing to even larger opposition landslides in local elections in the past. Still, Labor made unquestionably strong gains, and analysts said the biggest force working against the coalition remained the economy. Britain fell back into recession the first quarter of this year, bringing heaps of criticism from the opposition for the government’s dogged attempt to continue cutting spending — and the deficit — in the midst of an economic downturn. Cameron, however, insisted on Friday that the government would not be deterred from its fiscal crusade.

“These are difficult times and there aren’t easy answers,” Cameron said. “What we have to do is take the difficult decisions to deal with the debt, deficit and broken economy that we’ve inherited and we will go on making those decisions and we’ve got to do the right thing for our country.”

Yet the government has also been stung by a series of recent scandals, including the Conservative’s ties to media tycoon Rupert Murdoch. Murdoch — whose tabloid, TV and newspaper empire in Britain has been rocked by revelations of phone hacking and other illegal newsgathering methods — was described this week as “unfit” to run a global media company by a panel of parliamentarians. Last week, the government faced calls for the resignation of Cameron’s culture secretary, Jeremy Hunt, after a judge-led inquiry published 163 e-mails between Hunt’s office and a top lobbyist at Murdoch’s News Corp. The e-mails appeared to show that the government was attempting to smooth the way for News Corp.’s bid for full control of BSkyB, a satellite network.

Cameron is reportedly considering a major cabinet shake-up to get his government back on track, particularly as his administration faces allegations of incompetence. His ministers, for instance, have been unable to head off a border guard strike next week that has left Heathrow International Airport bracing for massive backlogs of arriving passengers. That followed several other missteps, including the perceived mishandling of a possible fuel-haulers strike.

“Voters don’t mind if you’re a heartless Conservative: You can be cruel, but efficient,” said Fraser Nelson, editor of the Spectator, a weekly British magazine. “But heartless and hopeless? Voters don’t like that at all.”