Neale Hanvey was the SNP candidate for the Kirkcaldy and Cowdenbeath constituency but was dropped in the run-up to Thursday's poll after social media posts he made two years ago came to light.
Despite his suspension, Mr Hanvey's name remained on the ballot paper next to the SNP logo as the deadline for candidates to be nominated had passed.
He took the seat from shadow Scottish secretary Lesley Laird, winning 16,568 votes to his Labour opponent's 15,325.
Mr Hanvey, who on apologising for the comments said he did not consider himself anti-Semitic but conceded the language he used was "unacceptable", said he has written to Jewish groups in a bid to make amends.
Speaking to the BBC before the result was declared, Mr Hanvey said he had made contact "to try to offer some reassurance that my apology is very sincere and also to help myself and others ensure that the language they use when they are talking about some of the sensitive issues is more measured".
On the SNP, he said: "I've got a lot of friends in the party, I feel at home in the party and I hope that this does not define me as an individual."
SNP leader Nicola Sturgeon said before the election that party members should not support Mr Hanvey, who is the subject of a disciplinary process, and should instead be going to other neighbouring constituencies to campaign for candidates there.
Ms Laird claimed Mr Hanvey continued to use SNP branding in his campaign despite being dropped as a candidate.