The attack at the Quebec Islamic Cultural Center came as worshippers attended evening prayers. Police Sgt. Christine Coulombe said 39 people escaped the shooting in the capital of the French-speaking eastern Canadian province.
The victims were aged 35 to 70, she added. Some of the wounded are in critical condition.
Police also said two suspects had been arrested, broadcaster CBC News reported.
Prime Minister Justin Trudeau and the province’s Premier Philippe Couillard described the incident in the Sainte-Foy neighborhood as an act of terrorism.
“We condemn this terrorist attack on Muslims in a center of worship and refuge,” Trudeau said in a statement. He added that Muslim-Canadians were “an important part of our national fabric and these senseless acts have no place in our communities, cities and country.”
In a tweet, Couillard added: “Quebec categorically rejects this barbaric violence. All our solidarity is with the relatives of the victims, the wounded and their families.”
He said the provincial flag would be flown at half-mast following the attack and, speaking at a news conference, condemned the “murderous act directed at a specific community”.
The attack started at around 8 p.m. Sunday local time (0100GMT Monday) when two masked suspects entered the mosque and started shooting, according to a witness who spoke to CBC’s French-language service radio.
3-year-old with father
“They started to fire and as they shot they yelled, ‘Allahu akbar’,” the witness said. “The bullets hit people that were praying. People who were praying lost their lives. A bullet passed right over my head.
“There were even kids. There was even a three-year-old who was with his father.”
Police said the situation was under control by 10:40 p.m. (0340GMT).
In a message on Facebook, the mosque called on people to await the preliminary results of the investigation before spreading rumors. “The situation is very critical but God willing we’re ready to endure it.”
The mosque’s president, Mohamed Yangui, was not inside when the shooting happened but said he received panicked telephone calls during and after the attack. “Why is this happening here? This is barbaric,” he told reporters.
Public Safety Minister Ralph Goodale tweeted that he was saddened by the deaths and his office said no motive had been confirmed.
The attack came amid widespread protests across the U.S. and elsewhere against President Donald Trump’s order banning immigrants and refugees from seven Muslim-majority countries.
Quebec has witnessed a number of Islamophobic incidents in recent months. In June, a pig’s head was left at the mosque’s door with a note reading “Bon appetit” during Islam’s holy month of Ramadan. The consumption of pork is prohibited for Muslims.
In 2015, a man in a mask in threatened Quebec’s Muslims in a YouTube video.