LONDON — It was just a one-off race out in a small district in Wales, where sheep outnumber voters, an off-year by-election to replace a Conservative Party lawmaker who was sacked by petition for cheating on his expense account. Normally, it would be back-page news.

But the Conservative Party candidate lost Thursday night — and a member of the anti-Brexit Liberal Democrat party won — and suddenly Prime Minister Boris Johnson’s working majority in Parliament has been reduced to a single seat. 

The government Johnson inherited from his ousted predecessor, Theresa May, was already dependent on the support of 10 lawmakers from Northern Ireland’s Democratic Unionist Party to get its wafer-thin majority. 

Now, the Conservatives are just one defection, resignation, scandal or death away from potentially losing that majority altogether. And Johnson will need every vote his whips can wrangle to pass his “do or die” Brexit through a fractured House of Commons.

Remember May’s Brexit deal? It was defeated three times in Parliament. Some Conservatives thought her deal was too weak. Others don’t especially want to leave the European Union. 

In a flash, the math has gotten worse for Johnson.

At the same time, he has made some lawmakers nervous with his insistence that Britain be prepared to leave the E.U. without a deal to manage the withdrawal, if the Europeans haven’t helped secure a new and better deal by the end of October.

Economists have warned that a no-deal Brexit could disrupt trade and cause pain on both sides of the English Channel.

On Friday, a wavering Conservative lawmaker, Philip Lee, said he was considering joining the Liberal Democrats. “I’m really not comfortable about my party pushing for no-deal Brexit without proper consent of the public,” Lee told the On the House podcast.

In February, three Conservative members of Parliament quit the party over Brexit to form a new independent group in the House of Commons.

There have also been five by-election contests since the 2017 general elections — two lawmakers faced recall petitions, two resigned from office and one died.

If Johnson’s pledge to get Britain out by October is threatened, many assume he might call a snap election to seek a greater majority in Parliament — but this result makes it unclear how he and his party would fare.

In the Brecon district by-election in Wales on Thursday, Conservative Chris Davies tried to hold on to his seat, but was beaten by Liberal Democrat candidate Jane Dodds.

What makes this doubly interesting is that the Liberal Democrats have emerged as the most potent voice in British politics for stopping Brexit and have increased their clout by forging a “Remain Alliance.”

In the election in Wales, the Liberal Democrats teamed up with other anti-Brexit parties, including the Greens and Wales’s Plaid Cymru, which both agreed not to put forward candidates, to increase the Liberal Democrat candidate’s chances.

“Boris Johnson’s shrinking majority makes it clear that he has no mandate to crash us out of the E.U.,” the Liberal Democrats’ new leader, Jo Swinson, said Friday. She added that she envisioned the Remain Alliance growing to fight Johnson’s Brexit plans.

“The country doesn’t have to settle for Boris Johnson or Jeremy Corbyn,” she told BBC Radio, referring to the opposition Labour Party leader, who can’t seem to make up his mind on whether Labour supports leaving or remaining in the E.U.

Dodd, the winner in Wales, said the Liberal Democrats “are the party that want to stay as part of the United Kingdom. We want to stay in Europe. We see that as healthy for our communities. We have to stay in Europe, and we have to stay in this bigger team.”

Guy Verhofstadt, a Belgian politician and a leader for the European Parliament’s Brexit talks, tweeted his congratulations to the Liberal Democrats, asserting that “the party goes from strength to strength & it really could change everything.”

The Liberal Democrats took 13,826 votes and the Conservative Party garnered 12,401, a margin of 1,425 that overturned the Tories’ previous majority of more than 8,000.

The voting district backed leave in the 2016 Brexit referendum.

Johnson was jeered this week as he visited Wales. The new prime minister met with chicken farmers and sheepherders who are worried that if Britain crashes out of Europe without new customs and trade arrangements, their roasters and lamb chops could immediately face high tariffs in Europe that would make their meats far less competitive.

“October, November and December are peak times to sell Welsh lamb,” Dodds said Friday. “There are two issues for farmers — firstly, how are they going to cope with 40 percent tariffs on their lamb exports. The second is mental health. Farming is the profession with the highest suicide rate. These are real concerns.”