Conservatives topped the first-preference votes in the contest at Fife Council in the Inverkeithing & Dalgety Bay ward.
Candidate Dave Coleman, who has served as the vice-chair of Dalgety Bay and Hillend Community Council, claimed the victory in the by-election.
The poll followed the resignation as a councillor of shadow Scottish secretary Lesley Laird, who was elected as Kirkcaldy & Cowdenbeath MP at last year’s general election.
The unsuccessful Labour candidate in the council by-election had received backing from former prime minister Gordon Brown, who lives in the area.
First-preference voting in the by-election, held using the single transferable vote (STV) system, was: C 2,309, SNP 1,741, Lab 744, LD 566, Ind Collins 521, Green 257, Ind Macintyre 40, Libertarian 13.
The turnout was relatively high at 43.1 per cent.
Meanwhile, Labour comfortably held three seats in council by-elections in England - at Tameside (Ashton Waterloo ward), Cumbria (Denton Holme division) and Carlisle (Denton Holme ward).