Britain’s governing Conservative Party suffered a crushing defeat in the contest for what had been considered one of its safer seats in Parliament, but avoided losing another district as results came in early Friday in three by-elections, a critical test of Prime Minister Rishi Sunak’s popularity.
The small, centrist Liberal Democrats party won in Somerton and Frome, in the southwest of England, overturning a big majority. In an emphatic victory, the Liberal Democrats received 21,187 votes against the Conservatives’ 10,790.
But there was better news for Mr. Sunak in Uxbridge and South Ruislip, in the northwestern fringes of London, where his Conservatives narrowly held on against the main opposition Labour Party in the district that had been represented by former Prime Minister Boris Johnson.
A third, critical contest — in Selby and Ainsty, in Yorkshire in the north of England — was still to be decided.
For Mr. Sunak, the by-elections were an anxious foretaste of the general election that he must call by January 2025.
Uxbridge and South Ruislip is the sort of seat that Labour has needed to win to prove that it is credibly closing in on power. Its failure to do so was attributed by the victorious Conservative candidate to public anger toward the mayor of London, Sadiq Khan, a Labour member, for his plans to extend a costly ultralow emission zone across all of London’s boroughs, including Uxbridge.
While the result could raise questions about Labour’s ability to win the next general election, the scale of the defeat in Somerton and Frome will most likely alarm Conservative lawmakers who are under pressure in some of the party’s heartland districts in the south of England.
With Britain besieged by high inflation, a stagnating economy and widespread labor unrest, his Conservatives face a real threat of being thrown out of power for the first time in 14 years.
While Britain shares some of these economic woes with other countries in the wake of the pandemic and Russia’s invasion of Ukraine, the Conservatives amplified the problems through policy missteps and political turmoil that peaked in the brief, stormy tenure of Mr. Sunak’s predecessor, Liz Truss.
She proposed sweeping but unfunded tax cuts that alarmed the financial markets and triggered her own downfall after on 44 days in office. Mr. Sunak shelved Ms. Truss’s trickle-down agenda and restored Britain’s fiscal stability. But her legacy has been a poisoned chalice for Mr. Sunak and his Tory compatriots with much of the British electorate.
“The Liz Truss episode really dented their reputation for economic competence, and that will be very hard to win back,” said Tim Bale, a professor of politics at Queen Mary University of London. “It’s going to be very difficult.”
So convincing is the Labour Party’s lead in opinion polls that some analysts predicted in advance that Mr. Sunak would become the first prime minister to lose three so-called by-elections in one day since 1968.
But the narrow victory for the Conservatives in Uxbridge and South Ruislip averted that prospect. There, when all votes were counted, the final tally was 13,965 for Steve Tuckwell of the Conservative Party, and 13,470 for Labour’s Danny Beales.
By-elections take place when a seat in the House of Commons becomes vacant between general elections. This time around, the contests were also a reminder of the toxic legacy of another of Mr. Sunak’s predecessors, Mr. Johnson.
Mr. Johnson resigned his seat in the district of Uxbridge and South Ruislip, on the western fringe of London, after lawmakers ruled that he lied to Parliament over lockdown-breaking parties held in Downing Street during the pandemic.
Voters in Selby and Ainsty in northern England were selecting a replacement for one of Mr. Johnson’s closest allies, Nigel Adams, who quit after not being given a seat in the House of Lords, as he had expected.
The contest in Somerton and Frome, a rural district in southwestern England, took place because another Conservative lawmaker, David Warburton, gave up his seat after admitting he had taken cocaine.
“This is probably the closing of a chapter of the story of Boris Johnson’s impact on British politics,” said Robert Hayward, a polling expert who also serves as a Conservative member of the House of Lords. But he added, “Whether it’s the closing of the whole book is another matter.”
Because the voting took place in very different parts of England, it provided an unusual snapshot of public opinion ahead of the general election. It also captured several trends that have run through British politics since the last general election in 2019, when Mr. Johnson’s Conservative won a landslide victory.
In Selby and Ainsty, a Tory stronghold, Labour hoped to show that it has regained the trust of voters in the north and middle of England — regions it once dominated but where it lost out to the Tories in the 2019 election.
The vote in Somerton and Frome was a test of the Conservative Party’s fortunes in its heartland areas of southern England, known as the “blue wall” — after the party’s campaign colors. It has been under pressure in the region from a revival of the smaller, centrist, Liberal Democrats.
The Liberal Democrats have benefited from some voters, who are opposed to the Conservatives, casting their ballots strategically for whoever seems best placed to defeat the Tory candidate.
Recent British elections have featured talk of a grand political realignment, with candidates emphasizing values and cultural issues. But analysts said these by-elections have been dominated by the cost-of-living crisis — kitchen-table concerns that hurt the Conservatives after more than a decade in power.