QUEBEC CITY (Reuters) - A former Canadian university student has pleaded guilty to killing six men who were praying in a Quebec City mosque in January 2017, a court said on Wednesday, averting a trial in one of the country’s rare mass shootings.

Slideshow ( 2 images )

Alexandre Bissonnette, 28, handcuffed and wearing leg irons as he entered the Quebec City courtroom, had asked on Monday to change his previous plea of not guilty.

Quebec Superior Court Justice François Huot accepted the new plea on Wednesday after taking steps to ensure Bissonnette understood the consequences of professing his guilt.

Speaking to the courtroom, which included members of the mosque, the Centre Culturel Islamique de Québec, Bissonnette asked the victims’ families for forgiveness and said he decided to plead guilty to spare them the hardship of a trial.

“I would like to ask forgiveness for all that I have done,” he said. “If at least by pleading guilty I can do a little good in all this, that would be something.”

Bissonnette did not explain why he had targeted the mosque but said he had held “suicidal thoughts” and an “obsession” with death.

“I am not a terrorist, nor an Islamophobe,” he said.

The judge declared him guilty on six counts of first-degree murder and six counts of attempted murder.

Congregants gathered at the courthouse said they were relieved to avoid a lengthy trial, but that it would be difficult for families to forgive Bissonnette.

“Our people are still in a state of shock. The sentence has to be pronounced. A lot of things have to happen,” outgoing mosque president Mohamed Labadi told reporters. “There is still a deep sadness, even though he has admitted his guilt.”

The slightly built, dark-haired Bissonnette looked down and at times wiped away tears as the judge read out the names of the mosque shooting victims.

Canadian Prime Minister Justin Trudeau initially described the shooting as a terrorist attack, although prosecutors did not charge Bissonnette with terrorism.

Police have described him as a “lone wolf” attacker.

Mass shootings are rare in Canada, where gun control laws are stricter than in the United States.

Sentencing arguments begin on April 10. Bissonnette faces at least 25 years in prison, and could receive concurrent sentences totaling more than 100 years.