With a defense tactic that sounds a lot more intriguing than the so-called Twinkie defense of years ago, a man in Sweden has gotten his rape conviction overturned -- by arguing he was sleeping when he had the sex.

The defendant earlier this year had been convicted and sentenced to two years in prison by a Swedish court, according to a report by the Agence France-Presse.

Then, earlier this month, Mikael Halvarsson took his case to an appeals court in the Scandinavian country, which ended up ruling in his favor and reversing the previous judgement on grounds the 26-year-old suffers from "sexsomnia" and did not intend to have sex with the woman he happened to be sharing a bed with.

A report said the alleged rape victim woke up after Halvarsson assaulted her and called the police, who, after they arrived, found him still sleeping in the bed in question.

A sleep disorder specialist testified on Halvarsson's behalf about the controversial condition in which it's believed a person can have sex while asleep, the news agency said, adding that the defendant's mother and former girlfriend both confirmed in court he demonstrated unusual sleep behaviors in the past.

All said, the Sundsvall appeals court afterward ruled the defendant "was in a state of sleepiness, unconscious of what was happening."

People are often left disoriented and fearful when something similar to what happened with Halvarsson happens to them, the news story said.

Kingman Strohl, a professor of medicine and director of research at the Sleep Center at Case Medical Center in Cleveland, told ABC News that sexsomnia is a confirmed medical diagnosis that does, in fact, involve unintentional sexual behavior during sleep.

"Usually people are very scared and also quite confused as to what's going on," he told ABC News about patients who suffer from the bizarre condition

The condition has not been looked on as favorably by the legal system.

Last month in Florida, 29-year-old Caleb Ruh was found guilty of molesting a 7-year-old girl in Florida in 2012.

He unsuccessfully argued he was asleed, under the influence of the drug Xananx, when, from a prone position on a couch, he called out to the girl, grabbed, touched and tried to kiss her.