QUEBEC -- Alexandre Bissonnette was driven by "racism and hatred" when he stormed into a Quebec City mosque and gunned down six worshippers in 2017, a judge said Friday as he sentenced him to 40 years in prison without possibility of parole.

Quebec Superior Court Justice Francois Huot began by saying the day of the murders "will forever be written in blood in the history of this city, this province, this country."

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.

Huot concluded a sentence of 50 years or more would constitute cruel and unusual punishment for the 29-year-old killer, and he declared that the section of the Criminal Code allowing consecutive life sentences violates the Canadian Charter of Rights and Freedoms.

While he did not strike down the section, he rewrote it to give himself the discretion to deliver consecutive life sentences that are not in blocks of 25 years, as had been the case. (First-degree murder carries an automatic sentence of life in prison with no possibility of parole before 25 years.)

Bissonnette pleaded guilty last March to six counts of first-degree murder and six of attempted murder after he walked into the mosque at the Islamic Cultural Centre during evening prayers on Jan. 29, 2017 and opened fire. The murder victims were Mamadou Tanou Barry, 42; Abdelkrim Hassane, 41; Khaled Belkacemi, 60; Aboubaker Thabti, 44; Azzeddine Soufiane, 57; and Ibrahima Barry, 39.

The sentence was denounced by survivors of the attack and other Muslim community members.

Aymen Derbali, who was shot seven times and left paralyzed from the waist down, told reporters he did not understand why the judge dwelled on Bissonnette's life expectancy and the possibility that he would die in prison.

"We were astonished, we were very upset after this sentence," Derbali said.

Boufeldja Benabdallah, president of the mosque that was attacked, said community members were "stunned" by the decision and felt the judge was more concerned about the dignity of the killer than that of the victims and their families.

"We want to appeal to Quebec society to understand us, to understand the pain we are in today, the disappointment we feel," he said.

Said El-Amari, who was wounded at the mosque, said the decision made him feel like "a Muslim Canadian citizen is worth less than any other citizen." He compared the sentence to that of Justin Bourque, who received 75 years without parole for killing three RCMP officers in New Brunswick in 2014.

"Nobody asked whether (Bourque) would have the time to get out and live in society or not," he said.

Ahmed Cheddadi, who was in the in the mosque at the time of shooting, said he worries the sentence could mean that some of the victims' young orphaned children "could one day run into their father's killer at the supermarket."

The Crown said it will take the time to study the 246-page decision before deciding whether to appeal. The defence also said it needs time to study the ruling.

Huot began the hearing by directly addressing Bissonnette, whom he ordered to stand in front of him.

"By your hate and your racism, you destroyed the lives of dozens and dozens of people, and have irredeemably ruined your own and those of the members of your family," he said before reading the sentence.

As the judge read a detailed account of the shooter's actions, several people in the Quebec City courtroom wept. Two women left in tears as Huot described how Bissonnette approached Soufiane as he lay on the ground, already wounded, and fired another bullet into his head.

The judge said that in the years leading up to the shooting Bissonnette increasingly drank alcohol and experienced anxiety, depression, and suicidal thoughts.

Huot noted that witnesses at his sentencing hearing testified that he had been severely bullied in school and had a documented history of mental health problems. He also lacked empathy, the judge said, quoting Bissonnette's statement after the shootings: "I regret not having killed more people."

The defence had argued Bissonnette should be eligible for parole after 25 years, but Huot said that would be too little.

The Criminal Code was amended in 2011 to allow a judge to impose consecutive sentences in cases of multiple murder, but it was clear as Huot spent nearly six hours reading the decision that he was wrestling with the constitutionality of the provision.

In the end he sentenced Bissonnette to concurrent life sentences for five murders, and on the sixth added 15 years to bring the total to 40. Huot expressed the hope that the killer would spend his sentence "regaining the humanity and dignity you left behind you," the day of the murders.

The longest prison sentence in Canada to date is 75 years without parole, which has been given to at least five triple killers since the law was changed to allow consecutive sentences.

Among the aggravating factors Huot cited in determining the sentence were the "well-planned and highly premeditated" nature of the crime, the number of victims, the fact they were in a house of worship and the hatred of Islam that motivated Bissonnette.

On the other hand, the judge said, Bissonnette had no previous criminal record, he pleaded guilty and he expressed remorse. He noted that Bissonnette's mental health problems contributed to his actions and judged the danger of him reoffending as "moderate" at most.

A decision on sentencing was originally expected in October, but Huot pushed that back, saying he needed more information on some legal questions, including the constitutionality of consecutive life sentences.

Witnesses at the time described the former Universite Laval student entering the Islamic Cultural Centre and calmly opening fire on the crowd gathered for evening prayers.

In addition to the men killed, five others were struck by bullets. The sixth attempted murder charge related to others who were nearby in the mosque.

The crime prompted an outpouring of horror and sympathy that reached across Canada and around the world, prompting a wider conversation on Islamophobia, intolerance, and the need for better understanding between communities. During a sentencing hearing last June, the conversation began to shift to the appropriate way to punish a crime that was, in many ways, unprecedented in Canadian history.

RECAP: Live updates from Quebec City courthouse. Can't see the feed below? Click here