Canadian Prime Minister Justin Trudeau reacted with "shock, sadness and anger" at the news of the fatal shooting in a mosque in Quebec City which left at least six people dead and injured eight others.

The gunmen opened fire during the evening prayers on 29 January. The police said 39 people survived the attack, and that two suspects were in custody.

The authorities have not yet specified what kind of weapon was used in the mass shooting at the mosque, which had a pig's head left outside the building last June, the Canadian Press reported.

Both Quebec Premier Philippe Couillard and Prime Minister Trudeau called the shooting a "terrorist attack" and a police spokesperson confirmed that a joint terrorism task force had been deployed to the scene of the shooting.

"Quebec categorically rejects this barbaric violence. All our solidarity to the victims, those injured, and their families. Let's unite against violence. Solidarity with the Muslim people of Quebec," Couillard said in a statement.

In his statement, Trudeau reminded Canadians that "diversity is our strength", a message that the Prime Minister has repeated in several occasions, particularly in reference to his refugee policy.

Trudeau's full statement read: "It was with tremendous shock, sadness and anger that I heard of this evening's tragic and fatal shooting at the Centre culturel islamique de Québec located in the Ste-Foy neighbourhood of the city of Québec.

"We condemn this terrorist attack on Muslims in a centre of worship and refuge.

"On behalf of all Canadians, Sophie and I offer our deepest condolences to the family and friends of all those who have died, and we wish a speedy recovery to those who have been injured.

"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.

"Muslim-Canadians are an important part of our national fabric, and these senseless acts have no place in our communities, cities and country. Canadian law enforcement agencies will protect the rights of all Canadians, and will make every effort to apprehend the perpetrators of this act and all acts of intolerance.

"Tonight, we grieve with the people of Ste-Foy and all Canadians."

Others leaders sent messages of grief and solidarity with the people of Canada. EU foreign policy Federica Mogherini responded to Trudeau's message: "The European Union is with Canada and with all Canadians in this sad day".

French President Francois Holland said in a statement : "I denounce with the utmost firmness the hateful attack that has killed at least six people and injured many in a mosque in Quebec."

"The terrorists wanted to attack the spirit of peace and tolerance of the citizens of Quebec," the president added. "France stands shoulder to shoulder with the victims and their families".

Chief of the NATO military alliance Jens Stoltenberg offered his condolences in a message on Twitter: "I condemn the horrific terrorist attack at a mosque in Quebec City. My thoughts are with the victims, their families & the Canadian people."

Pope Francis had been meeting archbishop of Quebec, Cardinal Gerald LaCroix, who was in Rome on 30 January, but cut his trip short to return to Canada. In a telegram, the pope said he was praying for those affected by the attack, condemning the violence. "[The Holy Father] begs the Lord for the gift of mutual respect and peace," the message read, as reported by the Associated Press.

The Vatican's office of relations with Muslims also condemned the killing at the mosque, saying in a statement that it "violated the sacredness of human life and the respect owed to a community in prayer in a place of worship."