Counting is under way in the Brecon and Radnorshire parliamentary by-election.
It is the first electoral test for new prime minister Boris Johnson.
The election was triggered after Tory MP Chris Davies was unseated by a petition that followed his conviction for a false expenses claim.
The turnout was 59.7%, down from 74.6% at the general election, but it is the highest for a by-election since Winchester in 1997.
Mr Davies was selected to stand again while Plaid Cymru asked supporters to back the Lib Dems to “coalesce” support among Remain parties.
The Green Party also did not put up a candidate to “maximise the chances” of a candidate most likely to beat the Conservatives and the Brexit Party.
In the 2017 general election, Mr Davies, 51, won the seat with a majority of 8,038, with the Lib Dems in second place.
But he lost it after 19% of voters in the constituency petitioned for the by-election.
The government’s working majority is two, including the confidence and supply partners. This will fall to one if the Conservatives lose.
The Lib Dem candidate is Jane Dodds, 55, the leader of the Welsh Liberal Democrats.
She lives in the neighbouring constituency of Montgomeryshire and is a child-protection social worker.
Brecon town councillor Tom Davies, a lawyer, is standing for Labour, who finished third at the last general election.
Des Parkinson, 71, a retired police chief superintendent, is standing for the Brexit Party.
He told BBC Wales: “It looks as if we’re running third at the moment. Coming third is what we thought would happen when we arrived here this evening.”
Mr Parkinson said he was sure there had been a “Boris bounce over the last week or so” to benefit the Tories.
Liz Phillips is the UKIP candidate while the Monster Raving Loony Party is also fielding a candidate.
Chris Wilkins, Theresa May’s former director of strategy, told BBC Wales: “I think at this stage of the evening it probably looks like a Liberal Democrat gain but maybe with a smaller majority than they would’ve hoped.
“That would allow the new prime minister to say that he has managed to get the Conservative vote up and squeeze the Brexit Party vote. If that’s the result, there’s something in there for everyone in that outcome.”
A Lib Dem source told BBC Wales it was “about as close as we thought it was always going to be”.
Labour candidate Tom Davies said speaking to some of his party’s voters, they felt it would be “safer to vote for the Lib Dems to make sure that Chris Davies did not get back in” but that this was tactical and they would switch back at a general election.
Polls closed at 22:00 BST and the result is expected in the early hours of Friday.