TORONTO -- A man who admitted to raping a sleeping woman years after being convicted of sexually assaulting her won a new trial Monday after arguing he was also asleep at the time of the attack.

However, in granting Ryan Hartman another hearing, Ontario's top court ruled the only issue to be decided will be whether he was suffering from a mental disorder at the time that made him not criminally responsible for the assault.

Hartman was convicted in May 2012 and sentenced to 14 months imprisonment for sexually assaulting the woman at a party in Brockville, Ont. He denied the assault had occurred but Superior Court upheld the conviction in December 2012.

In turning to the Court of Appeal, Hartman dropped his denial. Instead, he sought to introduce expert evidence to show he was suffering from sexsomnia and was unaware of his actions.

"New defences advanced years after the relevant events, only when other defences have been tried and failed and the convicted offender stands at the prison gate, must be viewed with considerable judicial suspicion," the Appeal Court said in its decision.

"However, there will be cases in which the interests of justice require that an appellant be allowed to present a new defence on appeal."

This was a rare occasion in which another hearing was warranted, the court said.

At trial, the complainant said she was sleeping on an air mattress in the kitchen with her boyfriend when she awoke in pain from someone penetrating her. She got up and turned on the light, and recognized Hartman.

"I'm sorry man, I just woke up making out with your girlfriend," Hartman told the boyfriend of the distraught woman, court records say.

The victim told police that Hartman was "just pretending" to be sleeping and "pretending to snore and breathe heavily" when she woke up.

Dr. Julian Gojer, a forensic psychiatrist, testified for the defence that some people are capable of complex activity while asleep but have no ability to control that activity. Hartman, he said, was "probably" asleep when he assaulted the woman.

"There is really no doubt in my mind that this individual had parasomnia," Gojer testified.

The Crown's doctor argued in rebuttal that Hartman was awake at the time, but drunk.

However, the Appeal Court accepted that Hartman had a history of sleepwalking as a child, that his family had a history of sleepwalking, and that his girlfriend had witnessed other incidents of his sexsomnia.

"A new trial is the appropriate order in these circumstances," the Appeal Court said.

Limiting the new trial to the question of whether Hartman is either guilty or not criminally responsible by reason of a mental disorder would help serve the administration of justice by validating the woman's assertion that she was in fact assaulted, the court said.