But he rejected the Crown's request for six consecutive life sentences, which would have prevented Bissonnette from seeking parole for 150 years and guaranteed that he end his life behind bars.
The killer's "highly premeditated" attack would be "written in blood" in Canadian history as one of the country's worst tragedies, Huot said in court.
While underscoring the brutality of the attack, Justice Huot suggested that such a harsh sentence would be excessive by denying the defendant the hope of ever leaving prison.
In a Quebec City courtroom on Friday, Quebec Superior Court Justice Francois Huot described Alexandre Bissonnette's crime as "gratuitous, covert and murderous", La Presse Canadienne news agency reported.
"We need to remember that sentencing is individual, it takes in a number of factors, and those include the circumstances of the crime, the severity, the impact on the community, but it also has to reference the circumstances and background of the offender", she said.
Abdelkrim Hassane, 41; Khaled Belkacemi, 60; Aboubaker Thabti, 44; Azzeddine Soufiane, 57; and Ibrahima Barry, 39, were all shot in the place of worship.
Alexandre Bissonnette, 29, will have to serve 40 years - longer than usual - before he can apply for parole.
This was a Reuters error as the judge was still reading his judgment.
"He really backed himself up, to use the expression", he said.
Several of the survivors and the victims' families had argued for a sentenced that required more than 25 years before parole eligibility, noting the heinous nature of the crime and the lasting trauma it caused for the Muslim community. Bissonnette's parents were also present.
In addition to the men killed, five others were struck by bullets.
But Bissonnette's lawyer, Charles-Olivier Gosselin, portrayed his client as an anxious and fragile man who deeply regrets his actions and is not beyond rehabilitation.