Pawel Rodak, 21, snapped when having consensual sex with 64-year-old Roger Gray at the Heriot-Watt University lecturer's home in the Merchiston area of Edinburgh in March last year.
Jailing Rodak, temporary judge Michael O'Grady, QC, called the case "tragic and difficult".
Judge O'Grady added: "Whatever the behaviour of the deceased, he can in no sense be said to have deserved his fate or brought it upon himself."
The judge added that he had decided against imposing a lifelong restriction on Rodak, but said his sentence must "afford the public protection from the killer".
Judge O'Grady ordered Rodak to be monitored in the community for three years after his release from prison.
The court heard Mr Gray's body was discovered by his upstairs neighbour on March 19 last year after he smelt gas coming from the ground-floor flat.
Police were called when an engineer was unable to enter the property and Mr Gray was found lying dead in his dressing gown in the hallway. The flat had been ransacked.
Rodak went on trial for murder earlier this year, but was convicted of culpable homicide on the ground of diminished responsibility.
Rodak claimed he suffered from post-traumatic stress disorder (PTSD), sparked by Mr Gray slapping him during a sex act.
The 21-year-old told the court he has been raped when he was 15. He claimed the slap had reminded him of this and had triggered the violence.
Once he had killed Mr Gray, Rodak left a lit candle next to four gas burners in the kitchen and fled.
But Rodak left behind a giveaway clue – his Polish bank card – which led to his arrest.
Mr Gray, a part-time lecturer in actuarial mathematics and statistics, died from massive blood loss after one of the stab wounds pierced his heart.
Rodak advertised on a gay website and told psychiatrists who examined him he had decided to become a male prostitute because he was short of money.
He said his first sexual experience had been at the age of 15 when he was violently assaulted by a 26-year-old man in Poland.
Rodak claimed Mr Gray had offered to double his fee if he inflicted pain on him with a whip. He also said Mr Gray had slapped him on the face.
He told consultant psychiatrist Dr Fionnbar Lenihan, 45, he decided to leave and Mr Gray followed him into the kitchen.
Rodak alleged Mr Gray pushed him, hit him again and said: "I'm paying you." Rodak claims he then picked up a knife from a table and warned: "I go wild, you know".
Dr Lenihan diagnosed Rodak as suffering from PTSD.
However, another consultant forensic psychiatrist, Dr John Crichton, who works alongside Dr Lenihan at the Orchard Clinic Medium Secure Unit in the Royal Edinburgh Hospital, argued Rodak was not suffering from PTSD when he carried out the killing.
If he had the condition, Dr Crichton said, he would not have put himself in a position of reliving the traumatic experience of being sexually abused by an older man.
Defence QC Murdo Macleod said: "He has no previous convictions whatsoever. He has always admitted he killed Mr Gray."
After the verdict earlier this year, Mr Gray's brother Fred said: "There is nothing that can bring my brother back. Our family can move on, but we will never forget Roger, who helped many people during his life."
Whatever the behaviour of the deceased, he can in no sense be said to have deserved his fate or brought it upon himself
Contextual targeting label: