The suspect in an attack on a suburban Quebec City mosque, Alexandre Bissonnette, has been charged with six counts of murder.
Bissonnette, a French-Canadian university student, also has been charged with five counts of attempted murder.
The attack came as worshippers were finishing their prayers, and has put Canadians on edge.
Government officials immediately labelled it a terrorist act. Police declined to discuss possible motives. "They consider this a lone wolf situation," a source said.
Quebec authorities have released the names of the six people killed. Khaled Belkacemi, 60, a professor at Laval University; Azzedine Soufiane, 57, a grocer and butcher; Abdelkrim Hassane, 41, an IT worker; Mamadou Tanou Barry, 42; Aboubaker Thabti, 44; and Ibrahima Barry, 39.
A spokeswoman for the Surete du Québec, the Quebec provincial police, said that two men had been arrested, though authorities later said that only one of the two men arrested is now considered as a suspect in the mass shooting at the Quebec Islamic Cultural Centre.
The Star reported that Bissonnette, 27, studied political science at Laval and played chess at the university with his twin brother.
A neighbour, Rosalie Bussieres, 23, told the Star he was "very solitary" and "very antisocial".
Professor Jean Sévigny, who last remembered seeing Bissonnette in 2015, said: "I can only give you the impression I had and that was that he seemed, he gave the impression of being a very good person".
NBC News reported that the suspect was known to troll Facebook pages dealing with immigration issues. A former classmate said he had seen Bissonnette comment on pages linked to a far-right, nationalist, anti-immigration movement and make anti-women comments online.
"His online life was full of hate, but in real life he was calm and his chess game was on point," the source told NBC.
On Bissonnette's Facebook page there were photos of him at a party, with family and with a chessboard. NBC said he had liked pages for heavy metal bands, video games and public figures ranging from far-right French politician Marine Le Pen to Pope John Paul II.
NBC reported that among the posts he had liked in recent months: a June posting on another person's page that read: "We live in a world where Christianity is demonised over cake and Islam is defended despite 50 dead at a gay club. Amazing."
Government officials wasted no time calling it an act of terrorism.
"This was a group of innocents targeted for practicing their faith," Canadian Prime Minister Justin Trudeau said in an address at the House of Commons. "Make no mistake: This was a terrorist attack."
Trudeau had earlier condemned the attack in a statement, adding: "While authorities are still investigating and details continue to be confirmed, it is heart-wrenching to see such senseless violence. Diversity is our strength, and religious tolerance is a value that we, as Canadians, hold dear."
Nineteen people were hospitalised at l'Hopital de l'Enfant-Jésus. Five victims remained in critical condition, hospital officials said, noting that 14 others had been treated and released.
Quebec Premier Philippe Couillard called the shooting a "terrorist act," saying that he reacted with "horror and incredulity" when he learned about the attack. He promised increased police protection for mosques and Islamic centres across the province of Quebec.
"We are with you," Couillard said, addressing the province's Muslim community. "You are at home. You are Quebecois."
At a subsequent news conference with Muslim leaders, Couillard said he could not theorise why members of the mosque were gunned down - but he acknowledged that they were the targets.
"This community was targeted, that's true," he told reporters. "The individuals who were attacked were attacked because they were part of this community."
But, he added: "All Quebecers have been the victims of this attack."
While mosques in Canada and the United States have been the targets of numerous acts of vandalism and other hate crimes in recent years, the Quebec City attack appears to be one of the first mass shootings at an Islamic house of worship in North America.
Witnesses said that a gunman or gunmen in hoods or ski masks opened fire on congregants at the mosque.
Police said the six people killed were between 35 and 60 years old, all men. Mosque officials said the victims were all Canadian citizens, and included men of Tunisian, Moroccan and Algerian descent.
One man was arrested close to the mosque, according to police.
A second man called emergency services about 20 minutes later, police said, and told a dispatcher that he wanted to talk. That person gave the dispatcher his location and waited for police about 22km east of the mosque along the shore of the St Lawrence River on the approach to a bridge leading to the Island of Orleans. He surrendered without incident and has been cooperating with investigators, police said.
Authorities have not publicly identified either of the two men who were arrested - and they said that one of the two is now considered a witness, not a suspect.
Authorities have not described the ethnicity or religious identity of the perpetrator. Neither of the two men who were detained was previously known to police, authorities said.
Charges are still being sorted out, police said. Authorities did not provide information about the type of firearms used.
Officials at the Quebec Islamic Cultural Centre urged followers not to spread rumours about the attack.
Still, the context of the attack was inescapable, coming after a rise in anti-Muslim rhetoric, behaviour and vandalism in the United States and Canada, amid a heated debate about President Donald Trump's executive order temporarily shutting US borders to refugees and migrants from seven mostly Muslim countries.
While debate has raged in the US over whether to accept refugees from war-torn Syria and elsewhere, the Canadian Government has become more open to people fleeing conflict in the Middle East. Trudeau has personally greeted some refugees who have entered the country, and said he welcomed people who were rejected from the US under Trump's order.
Muslims in both Canada and the United States have reported a surging number of hate crimes in recent years, including vandalism, assault and arson at their places of worship.
The Quebec Islamic Cultural Centre, one of several mosques in the area, was the target of an apparent hate crime in June, when someone left a bloody pig's head wrapped in cellophane at the front door, along with a note reading, "Bonne appétit." The consumption of pork is banned by Islam. Concerned about that kind of incident, the mosque installed several closed-circuit cameras around the building.
"All our thoughts are with the children, whom we must tell about the death of their fathers," the mosque stated on its Facebook page. "May Allah give them patience and endurance."
The director of the National Council of Canadian Muslims said that he was "horrified by this despicable act of violence".
"This act of wanton murder must be punished to the fullest extent of the law," Ihsaan Gardee, the director, said.
"We are heartened by the overwhelming support from fellow Canadians in this time of deep crisis," he added. "We must unite together against divisive forces that seek to harm our communities."
There are more than 1 million Muslims in Canada. About 6000 live in Quebec City, according to Canada's 2011 National Household Survey.
- additional reporting AP, AAP