The Liberal Democrats have won the Brecon and Radnorshire by-election, leaving new PM Boris Johnson with a Commons working majority of just one.
Jane Dodds overturned an 8,038 majority to beat incumbent Conservative Chris Davies by 1,425 votes.
Mr Davies decided to stand again after being unseated by a petition following his conviction for a false expenses claim.
It was the first electoral test for Mr Johnson since becoming prime minister.
Now, with a particularly wafer-thin working majority, he will have to rely heavily on the support of his own MPs and his confidence-and-supply partners the DUP to get any legislation passed in key votes.
It was also a bad night for Labour, whose vote share dropped by 12.4% as they were beaten into fourth place by the Brexit Party.
Ms Dodds, who is the Welsh Liberal Democrat 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.
Prof Laura McAllister, from the Wales Governance Centre at Cardiff University, said the result should not be read as a “resounding result” for Remain.
She pointed out that the three Brexit-supporting parties had 2-3,000 votes more than the remain alliance.
But she added: “There are always nuanced undercurrents to this. The reality is Brexit isn’t the only issue people were voting on.
“People were probably voting on rural and local issues. We can never categorically say this was about Brexit.”