The Liberal Democrats’ by-election win in Brecon and Radnorshire has left new Prime Minister Boris Johnson with a House of Commons majority of just one.
Jane Dodds overturned an 8,038 majority to beat Conservative Chris Davies by 1,425 votes.
Former MP Mr Davies stood again after being unseated by a petition that followed his conviction for a false expenses claim.
It was the first electoral test for Mr Johnson.
His government’s working majority was cut to one, including its confidence and supply partners.
Labour were beaten into the fourth place by The Brexit Party.
Ms Dodds, who is Welsh Lib Dem leader, said: “My very first act as your new MP when I get to Westminster will be to find Mr Boris Johnson, wherever he’s hiding, and tell him to stop playing with the future of our community and rule out a no deal Brexit”.
Mr Davies congratulated Ms Dodds saying “I wish her well for the future” and he paid tribute to his family saying they had “a difficult time over the past few months”.
The turnout was 59.6%, down from 74.6% at the general election, but it is the highest for a by-election since Winchester in 1997.
Both Plaid Cymru and the Greens did not field candidates, to try to maximise the Remain vote.
Plaid leader Adam Price said the “spirit of co-operation” between the pro-Remain parties had led to Ms Dodds’s election, as he called for a second referendum.
“But if the prime minister is intent on a general election, he should know that Plaid Cymru and the other pro-Remain parties are committed to cooperating so that we beat Brexit once and for all,” he added.
Ms Dodds, 55, lives in the neighbouring constituency of Montgomeryshire and is a child-protection social worker.
The Lib Dems regained the rural seat – which it had held for all but nine of the last 34 years and lost at the 2015 general election.
Recently-elected Lib Dem leader Jo Swinson said: “Boris Johnson’s shrinking majority makes it clear that he has no mandate to crash us out of the EU.”
Labour, which at one stage feared it might lose its deposit, blamed voters switching tactically to the Lib Dems.
A spokesman for Welsh Labour said: “We always knew this was going to be a difficult night for us, but we’re proud of our positive campaign in Brecon and Radnorshire”.
“One thing is clear – voters have rejected Boris Johnson and his divisive, out-of-touch UK Tory government.”
Political analyst Prof Roger Awan-Scully, from Cardiff University, said: “Labour need to look very closely at this result. Everything points to not just tactical voting for the Lib Dems but also dissatisfaction with Jeremy Corbyn and [First Minister] Mark Drakeford”.
The Brexit Party’s Des Parkinson, a retired police chief superintendent, who finished third, said: “If you look at the actual total of the vote, the Brexiteers won.
“It shows where the votes are but the prime minister has to deliver a clear Brexit… if he doesn’t, then his government is in dire trouble”.
The Monster Raving Loony Party pushed the UKIP candidate into sixth place.