Jordan Hipkins, 24, of North Street, York, pleaded guilty to manslaughter on the day he was due to stand trial for causing the death of 44-year-old James Moore.
He was jailed yesterday at York Crown Court, where he also received two further three-month jail terms for unconnected offences including assault and criminal damage after attacking a taxi and its driver, and obstructing a police community support officer in a separate incident.
A charge of possessing a knife was allowed to remain on file.
North Yorkshire Police were called out to Micklegate in the early hours of May 25 last year as paramedics performed CPR on an unconscious Mr Moore.
Mr Moore, of no fixed address, was resuscitated and taken to hospital where he remained in a critical condition until he died on June 5.
The police investigation placed Jordan Hipkins with Mr Moore on the morning that he became ill.
CCTV footage showed Hipkins injecting Mr Moore with a substance that turned out to be heroin.
A post-mortem examination showed that Mr Moore died from the effects of heroin and alcohol.
Detective Constable Michael Johnston, of the York Serious Crime team, said: “Hipkins waited until the very last minute to admit his guilt, putting Mr Moore’s only surviving relative through the ordeal of the court process until he eventually pleaded guilty.
"Our thoughts remain with Mr Moore’s sister who has not only endured the loss of James, but had to see him suffer in the days leading up to his death.
"I hope they take some comfort that Hipkins has now been held accountable for his death.”