Christopher Blaikie, 24, stabbed Claire Mazzucchi in the neck with a knife during a field trip to study the behaviour of animals.
A court heard the psychology student became agitated and had been suffering obsessive thoughts before the attack on 30 March last year.
Judge Lord Turnbull described it as a "difficult" case.
A court was told former Stirling University student Blaikie was admitted to hospital on a voluntary basis because he had been experiencing obsessive thoughts.
However, he was not diagnosed with Asperger syndrome until he was admitted to the State Hospital in Carstairs following the offence.
Ms Mazzucchi, 22, had been living in the same flat as Blaikie but had left because she felt uneasy.
During the lunch break Blaikie started banging his cutlery, then walked over to Ms Mazzucchi's table where he put his right hand over her face and put her in a headlock.
After making stabbing motions, he struck her once on the left hand side of her neck with a knife.
Another student got up and pulled Blaikie away from Ms Mazzucchi, who was severely injured and needed surgery.
Defence lawyer Lorenzo Alonzi said: "We have a man who has no previous record and who was under considerable stress at that time and who had even identified that he was in a stressful condition and had attempted to get help.
"Regrettably, the help that he did get didn't quite reach the mark."
Lord Turnbull jailed Blaikie for two years at the High Court in Aberdeen and ordered him to be the subject of a supervised release order after his term of imprisonment.
A man who attempted to murder his classmate at Blair Drummond Safari Park has been jailed for two years.