Scott Peden, 30, was bidding to make a super-strength form of cannabis at the flat in Tollcross when the equipment caught fire and blew up on 21 March.
Several people were badly injured and a dog and cat were killed.
At the High Court in Glasgow, Peden admitted culpable and reckless conduct and producing a controlled drug.
Jailing him, judge Lord Armstrong told Peden that he had shown “gross irresponsibility” and that his actions had “traumatic and devastating consequences”.
The court heard that Peden had set up the lab in his girlfriend’s flat in Fairburn Street in a bid to produce “shatter”, the street name for Butane Honey Oil, which is a concentrated form of cannabis.
Prosecutor Iain McSporran said this involved using “laboratory grade equipment” such as tubes, butane gas and a specialist “vacuum oven”. On 21 March, a gas released during the drug-making process ignited and caused an explosion.
The court was told this could have been caused by a light being turned on.
Windows and the front door of the flat were instantly blown off due to the power of the blast.
As the resulting fire quickly spread, Peden and two friends fled while neighbours also tried to escape.
One neighbour, Alexander Elder, was badly injured after climbing out of his second-floor flat window.
Two others, Ewa Uscitowicz and Robert Andrezjewski, were knocked unconscious as thick smoke engulfed the building.
Firefighters arrived following a flood of 999 calls and eventually rescued those still trapped.
The operation to extinguish the flames took about two hours.
A total of eight residents required hospital treatment for injuries including burns, smoke inhalation and carbon monoxide poisoning.
It was initially feared Mr Andrezjewski and Ms Uscitowicz may die.
Mr Elder suffered multiple broken bones from his fall. A cat and a dog were also killed.
The court heard that Peden’s two friends were also badly burned.
Peden could not initially be traced after he fled and it was only on 31 March that he handed himself in to police.
He admitted being in the kitchen at the time of the blast, but said it was an “accident”.
Peden – who also had minor burns – added his girlfriend had not been at the flat for around two months.
After Peden was jailed, Det Insp David Stewart, of Police Scotland, said: “When emergency services attended at the scene of the incident at Fairburn Street they were faced with scenes of absolute carnage.
“It was determined that Peden had been manufacturing a concentrated cannabis derivative.
“An explosion followed as a result of his idiocy.”
The detective added: “I cannot emphasise enough the stupidity of his selfish actions.
“It borders on the miraculous that his neighbours, his friends within the flat and Peden himself were not more seriously injured, or indeed killed, as a consequence. The sentence handed down today reflects the gravity of his crimes.”