QUEBEC — When Alexandre Bissonnette learned of Justin Trudeau’s now-famous tweet welcoming refugees to Canada, the waif-like 28-year-old political science student told police that he snapped.

Just hours after watching a television report suggesting Canada would accept immigrants spurned by President Trump, Mr. Bissonnette packed his Glock handgun and rifle, picked up a bottle of Smirnoff Ice, and trudged the snow-covered streets of Quebec to a nearby Islamic Cultural Center.

As 53 men were finishing evening prayers, he unloaded 48 rounds. Six people were killed — several of them by shots to the head — and 19 were injured, one paralyzed for life.

These details surfaced during a three-week sentencing hearing that ended late last month. Mr. Bissonnette faces up to 150 years in prison after pleading guilty to six counts of first-degree murder and is expected to be sentenced in the coming months.

The hearing was a grim reminder that more than a year after the Jan. 29, 2017, rampage, Canada is still grappling with Mr. Bissonnette’s crime. It shocked the nation and underlined the perils of Islamophobia and the far right in a country that prides itself on its multiculturalism and tolerance.

Herman Deparice-Okomba, director of the Montreal-based Center for The Prevention of Radicalization Leading to Violence, said the sheer obscenity of someone gunning people down in a place of worship in peace-loving Canada had convulsed the country because it shattered Canadians’ image of themselves as the ultimate humanistic, open nation.

“Canada sees itself as a nation of immigrants, and people thought that such a thing was impossible here,” Mr. Deparice-Okomba said. “Bissonnette’s crime wasn’t just against a community. It was against Canada’s collective vision of itself. We are all wounded.”

During the often chilling hearing, prosecutors, survivors, prison psychologists and people who knew Mr. Bissonnette painted a portrait of a socially isolated but intelligent young man who developed an obsession with the far right, mass killers, Donald Trump and Muslims.

Sometimes it felt as if Islamophobia was on trial. Mr. Bissonnette was not charged with terrorism, prompting outcries from Muslim groups that, if his name had been Muhammad, the charges would have been different.

Under the Canadian Criminal Code, the burden of proving terrorist intent is high, and legal experts said prosecutors likely concluded that securing a first-degree murder conviction would be less risky.

Some survivors testified they were too afraid to return to the mosque. In a strictly secular province that recently passed a law banning people wearing face-coverings from giving or receiving public services, the court allowed Muslim witnesses to swear on a Quran.

Acting alone, Mr. Bissonnette also raised a difficult question: How did a mousy and soft-spoken chess-obsessed student from a middle class family become a killer?

In the month before his rampage, he trawled the internet 819 times for posts related to Mr. Trump, reading his Twitter feed daily and homing in on the American president’s travel ban on several Muslim-majority countries. He kept a cache of guns underneath his bed at his parents’ house. Among his only friends was his twin brother, Mathieu.

Mr. Bissonnette told investigators he wished he had killed more people, and had wanted to protect his family from Islamic terrorists.

“I was, like, sure that they were going to come and kill my parents also, and my family,” he said in a video of a prison interrogation played in court.

During the hearing, Mr. Bissonnette was handcuffed and his tiny frame was covered in a baggy sweatshirt. He fluctuated between stony silence and tears from inside a glass enclosure, flanked by two police officers.

He was impassive while Megda Belkacemi, the 29-year-old daughter of one of the victims, the university professor Khaled Belkacemi, testified about seeing her father with a hole where one of his eyes should have been.

But when the judge called his parents “collateral victims” of the attack, he sobbed.

Mr. Bissonnette’s erratic personality was also revealed in a haunting 50-minute 911 call — played in court — in which he turned himself in. He repeatedly told the operator he was going to shoot himself.

“I’m sick of this,” he said, adding: “I’ve never hurt anyone.”

Throughout the proceedings, Mr. Bissonnette’s parents, Manon Marchand and Raymond Bissonnette, a public sector worker and a lawyer, sat stoically in the front of the courtroom’s public stalls, overflowing with families of the victims. At one point, the couple comforted a woman in a head scarf.

Experts on radicalization said that in Quebec, a French-speaking province surrounded by an English-speaking majority, the anti-immigrant far right offered fertile and perilous ground for psychologically unstable youths like Mr. Bissonnette seeking a sense of identity and a scapegoat.

Mr. Deparice-Okomba said Mr. Bissonnette was part of a growing number of educated, middle-class youths in Quebec drawn to far-right ideas, fueled by the election of Mr. Trump and fanned by fears that immigrants threatened Quebec’s identity.

When he started the center in 2015, he said it dealt with 17 cases of youths in the province radicalized by the far right. Last year, the center had 154 such cases, he noted, compared with 126 cases of youths radicalized by Muslim extremism.

Nevertheless, he stressed that far-right groups in Quebec like La Meute, or Wolfpack, which castigate Islam, remained marginal.

“Youths here typically don’t get radicalized because they feel discriminated against since Canada is such an inclusive society,” he said. “Rather, they get radicalized due to ideological convictions. They feel they must do something to prevent catastrophe.”

The internet also appears to have provided Mr. Bissonnette with both a forum and a pretext to vent his rage.

François Deschamps, who ran a web page raising money for Syrian refugees, said Mr. Bissonnette had spent months trolling the group’s Facebook page.

“He liked to express views that were ultraconservative, racist and anti-Muslim,” he said, “He would also go to event pages of feminist groups and write ‘FemiNazis.’ ”

Like last month’s Toronto attacker, Alek Minassian, a 25-year-old who fatally ran over 10 pedestrians with a rental van, Mr. Bissonnette was preoccupied by Elliot Rodger, the man who killed six people in Isla Vista, Calif., in May 2014 after railing about his failures with women.

Mr. Bissonnette also browsed websites linked to the white nationalist Richard Spencer, the former Ku Klux Klan leader David Duke, and Dylann Roof, the white supremacist who killed nine African-Americans at a South Carolina church.

The hearing raised the thorny question of whether bullying — and society’s failure to prevent it — had pushed Mr. Bissonnette on his deadly course.

Lucie Côté, a French teacher who taught Mr. Bissonnette in high school, told the court that he was mercilessly picked on by students, laughed at and shoved against the wall.

“Alexandre developed nervous reflexes, reflexes of fear,” she said. “Alexandre was not a monster.”

Acquaintances who knew Mr. Bissonnette at Université Laval said he was “that student nobody notices.” He joined a chess club, hunted and sought refuge on a shooting range. In the weeks before the attack, he became withdrawn, friends said.

Éric Debroise, who led a political discussion group at the left-leaning Université Laval, recalled that Mr. Bissonnette arrived for the first get-together at a bar wearing a shirt and tie when everyone else was in T-shirts and jeans.

When he immediately brought up the National Front and Marine Le Pen’s immigration policies, Mr. Debroise said he cut him off, and he sulked in silence.

Consumed by anxiety and depression, Mr. Bissonnette told police he contemplated suicide at 16. He developed an alcohol problem. He wanted to become a pilot but got a job at a call center instead.

After Michael Zehaf-Bibeau, a Muslim, attacked the Canadian Parliament in October 2014, Mr. Bissonnette bought his first gun. It was one of several he would purchase legally, omitting his psychological problems from application forms, according to Marc-André Lamontagne, a psychologist who interviewed him in prison.

Six weeks before the mosque attack, Mr. Bissonnette told Mr. Lamontagne he went to a Quebec City shopping center to kill people and himself, but couldn’t go through with it.

“He had fantasies to do something big so that people would not laugh at him after his death, so that people would remember him,” Mr. Lamontagne said.

At the Quebec mosque, its windows still pocked with bullet holes, the Muslim community is still struggling to come to terms with the attack and their fear and grief.

The mosque’s president, Mohamed Labidi, said anti-Muslim incidents intensified before and after the attack. Before the killing, a severed pig’s head was left on the mosque’s doorstep. When he announced plans to build a Muslim cemetery on city land six months after the attack, his car was set on fire.

He blamed far-right groups and anti-immigrant “trash radio” hosts for creating a “toxic climate.”

Amir Belkacemi, the son of Khaled Belkacemi, said his father had come to Canada from Algeria in the 1990s to escape terrorism, only to become ensnared by violence here. Still, he said he had no intention of leaving the place he calls home.

“Quebec didn’t create the monster Alexandre Bissonnette,” he said. “But the Islamophobia here gave him his motive.”