The Penicuik by-election was won by SNP candidate Joe Wallace at stage three using the single transferable vote system.
The by-election was called following the death of Labour councillor and provost, Cllr Adam Montgomery.
After three rounds of transferred votes, Mr Wallace tallied up 2,237 votes compares to Conservative candidate Murdo Macdonald’s 1,788 votes.
The election turnout was 42.9 per cent.
The result means the SNP are now the biggest group on the council with seven elected members, ahead of Labour on six and the Conservatives with five councillors.
SNP Business Convener Derek Mackay MSP said: “After nearly eleven years in power at Holyrood, the SNP continue to win elections the length and breadth of Scotland, as people continue to place their trust in us to stand up for Scotland and local communities.
“This is a great result for residents in Penicuik and across Midlothian, with the SNP now the largest party on the council.
“And despite Labour throwing the kitchen sink at this seat they could only manage third place.
“Many congratulations to the local campaign team and Joe Wallace for this fantastic victory – Cllr Wallace will join a strong SNP group who are delivering for communities across Midlothian.”
Join our Facebook group Our Edinburgh to share images and news from and around the Capital