The man, who is in his 50's and lives in central Sweden, told both the first and the second trial that he had not been aware he had had sex with the girl until she turned out to be pregnant and a DNA test in March revealed him as the father.
The girl confirmed that the man had been asleep, but said that she had allowed the sexual intercourse to continue in the hope that his wife would wake up and leave him.
The district court did not believe their stories and sentenced the man to two and a half years in prison for raping a minor.
However, on Tuesday the appeals court Svea Hovrätt threw out the verdict. It said the prosecutor had not managed to prove beyond doubt that the man was not asleep at the time he had sex with the girl.
“My client is of course very relieved. He has, from day one, professed his innocence and it has been an uphill fight for us. When you're accused of this type of crime, which is very serious, you almost have to prove your innocence rather than the other way around,” his lawyer Jimmy Schiöld told the Aftonbladet tabloid.
The girl's legal representative declined to comment when approached by the newspaper. The prosecutor meanwhile said she had not decided whether or not to appeal to the Supreme Court.
The condition of sexsomnia, from which the man is not believed to have been suffering at the time, according to Aftonbladet, came to national attention in 2014 when a suspected sleeping rapist in northern Sweden was cleared by an appeals court.
With a number of similar cases cropping up in Sweden over the past decade, a prosecutor in May this year put together new guidelines for courts, recommending that they call on sleep experts whenever necessary.
Her team said that a court should pay special attention to testimony from a defendant stating that a suspect seemed groggy and confused or, conversely, appeared wide awake and fully conscious of what was happening throughout an alleged sexual assault.