SNP candidate Rob Munn has won the Leith Walk by-election - with his party now tied with the Conservatives as the biggest group at City Chambers.
Cllr Munn won 35.7 per cent of first preference votes, ahead of Green candidate Lorna Slater who took a 25.5 per cent share of first preference votes. In a disappointing night for Labour, Nick Gardner received just 15.5 per cent of first preference votes - with Tory candidate Dan McCroskrie taking 10.7 per cent and Lib Dem candidate Jack Caldwell winning 8.6 per cent of first preference votes.
The SNP victory means the coalition partner is now tied with the Conservatives with 17 councillors apiece on the city council. The by-election was being held after former Labour councillor Marion Donaldson resigned in January. The election had a turnout of 30.3 per cent - with 7,267 votes cast.
Cllr Munn previously served as councillor for the Leith Harbour ward from 1996 until 2003 before returning to the council for the Leith ward in 2007. But in 2012, he failed to get re-elected.
The single transferable voting system means that candidates are ranked in order of preference and must reach a certain threshold in order to get elected. Votes from candidates in last place at each stage are redistributed to the voter's next choice.
The SNP and Green vote remained fairly steady until round seven, when Ms Slater started to close the gap. By the end of round 10, only 256 votes separated the leading candidates.
Speaking after his victory, Cllr Munn said: "It was a busy campaign and personally I had quite a lot riding on it in taking the chance to come back in a by-election.
"I expected the Greens to do well and at some stages I was quite concerned.
"For a number of reasons, the ward has had a turbulent recent history in terms of councillors. There's a lot happening in the ward that needs to be addressed."
Independent candidate Kevin Illingworth, standing on behalf of the Save Meadowbank campaign, won 110 first preference votes, ahead of UKIP's Steven Alexander who only secured 85 first preference votes.
David Jacobson from the Socialist Labour Party won 56 first preference votes, independent candidate John Scott secured 16 votes, Paul Stirling from the For Britain Movement tallied up just 14 votes and Libertarian Party candidate Tom Laird chalked up 12 first preference votes. There were 67 rejected ballot papers.
Green politicians celebrated overtaking Labour into second place for first preference votes.
Ms Slater said: “I can’t think of a more turbulent backdrop to this election – with Brexit chaos and parties gearing up for a European election campaign. So that is why I am so delighted to have beaten Labour in the ward.
"Of course, I would love to have gone that bit further but the result shows just how strong Green support is here in Leith Walk."
Labour group leader, Cllr Cammy Day, said national issues had contributed to his party's disappointing night.
He said: "I think Nick fought a hard battle on local issues. It's quite clear that national issues played a part in this. People are getting turned off politics because of national issues.
"I hope to see Nick back on the council in the next local government elections, if not before. He has really championed local issues and I think people really respect that."
Council leader, Cllr Adam McVey praised his party colleague's victory.
He said: "Rob ran a fantastic campaign and I'm delighted to welcome him back onto the council.
"We took a positive message to the people of Leith Walk. We had a fantastic candidate in Rob and I'm thrilled he's joining the team that is taking the city forward."