Plaid Cymru's Lindsay Whittle won the Senedd MP seat with 47.4% of the vote, beating Reform's Llŷr Powell by more than 11 percentage points.
The results were a disappointment for right-wing parties, with UKIP receiving a "comically low" number of votes, finishing last.
Labour, who had held the seat for over 100 years, saw their vote collapse to 11%, while the Tories, Lib Dems, and Greens combined received 5%.
'Stop Farage' campaign denies Reform a win in Wales
Author's summary: Plaid Cymru wins Caerphilly by-election.