Labour has retained the Livingston seat at Westminster with a reduced majority in a by-election prompted by the death of former Foreign Secretary Robin Cook.
Its candidate Jim Devine, 52, who was Mr Cook's election agent, polled 12,319 votes, giving him a majority of 2,680 over the SNP, down from 13,097 in May.
The result is a swing of 10.2% to the nationalists. Turnout was 38.6%, a fall from 58.1% at the general election.
Labour also kept the Cathcart seat at Holyrood, but with a smaller majority.
After the declaration in Livingston, Mr Devine said he hoped to emulate Robin Cook's performance as an MP.
"This is not a place that anyone wanted to be, far less myself," he said in his acceptance speech.
Jim Devine (Lab):12,319
Angela Constance (SNP):9,639
Charles Dundas (Lib Dem):4,362
Gordon Lindhurst (Cons):1,993
David Robertson (Green):529
Steve Nimmo (SSP):407
Peter Adams (UKIP):108
Melville Brown (Ind):55
John Allman (Alliance for Change):33
Brian Gardner (Socialist Party of GB):32
"Robin Cook was an outstanding parliamentarian within this constituency. He served this constituency with distinction for many years.
"Throughout the town and the constituency there are many monuments to his great work that he carried out.
"Let me say, I hope to continue the work."
Mr Devine, a trade union official with Unison, has held several key positions within the party in Scotland and had been Mr Cook's agent since the 1983 election.
Mr Cook, 59, collapsed and died while hillwalking in north west Scotland in August.
The late MP was foreign secretary between 1997 and 2001, when he was demoted to the post of Commons leader.
In 2003, he resigned from the Cabinet on the eve of the Iraq war, declaring that military action was unnecessary.
Robin Cook: "Served constituency with distinction"
The SNP candidate Angela Constance polled 9,639 votes with the Liberal Democrats' Charles Dundas taking 4,362.
The Conservatives' Gordon Lindhurst won 1,993 votes, the Greens' candidate David Robertson 529 and Steve Nimmo, of the Scottish Socialist Party 407.
The swing from Labour to the SNP in Cathcart was 3.66%.
BBC Scotland political editor Brian Taylor said: "The SNP have made progress but the swing in Cathcart is frankly a substantial disappointment to the largest opposition party in Scotland.
"The story of the night in my view always is who wins and the Labour Party have won in both."
The SNP leader Alex Salmond, who has set his sights on winning the 2007 Scottish Parliament elections, described the results as "highly satisfactory" for his party.
"If replicated across the country the Livingston swing would deliver the SNP 28 additional seats in the Scottish Parliament elections in 2007 and on the swing in Cathcart we would win nine extra," he said.
"No other party made a fraction of our progress across the two seats.
"With that debate settled, the SNP can get on with our preparations to gain the 20 seats required to become the leading party in Scotland."