Ian Murray has held onto Labour's Edinburgh South seat
One of the most closely fought battles of the election has been won by Labour as it has held on to Edinburgh South.
One of the Liberal Democrats' top targets, the seat went to a recount with Labour receiving a reduced majority of just 316 votes.
Winning Labour candidate Ian Murray told cheering supporters: "I haven't got anything prepared because I didn't expect to be standing here."
Labour was defending a 2005 majority of just 405 over the Liberal Democrats.
The previous MP Nigel Griffiths was caught in a sex scandal, which was further expected to damage the party's hopes of holding on to the seat.
Chancellor Alistair Darling, who held on to his Edinburgh South West seat with an increased majority of 8,447, branded the SNP and Tory challenge as miserable and pathetic.
Elsewhere in the capital, Labour held on to its seat in Edinburgh North and Leith with Mark Lazarowicz beating Liberal Democrat Kevin Lang to the post with a majority of 1,724.
Michael Crockart held the Liberal Democrat's Edinburgh West seat with 16,784 votes. Labour's Cameron Day came second with 12,881 votes.
Labour held on to East Lothian, the seat where Anne Moffat was deselected by the party in March. Fiona O'Donnell took 44.6% of the votes and increased the party's constituency majority to 12,258 over the Tories.
Alistair Darling increased his majority in Edinburgh South West
In West Lothian, Labour held its seat in Livingston with Graeme Morris securing a 48.5% of the vote and Michael Connarty held the party's seat in Linlithgow and East Falkirk.
Labour also held Midlothian's seat with David Hamilton taking 18,449 votes over second place Colin Beattie of the SNP who got 8,100 votes.
Thomas Docherty took 46.3% of the vote to win back former Labour seat Dunfermline and West Fife, which was lost to the Lib Dems in a 2006 by-election.
Gordon Brown held Kirkcaldy and Cowdenbeath with 29,559 votes over second place Douglas Chapman of the SNP who got 6,550 votes.
The former Liberal Democrat leader Sir Menzies Campbell held his Fife North East seat after securing 17,763 votes and a 9,048-majority over the Conservatives.
Labour's Lindsay Roy held the seat in Glenrothes with 62.3% of the vote.