"I strongly condemn the attacks on the Canadian military personnel in Quebec and Ottawa and the shooting in the Canadian parliament in Ottawa," Modi said in a statement released by the external affairs ministry.
"A parliament is a temple of democracy and holds a special place in the hearts of those who believe in democratic ideals.
"As a nation that has experienced a horrific terrorist attack on its parliament, we share the sense of outrage and trauma of the people of Canada over the attack on the highest institution of democracy," Modi said, referring to the December 2001 attack on Indian parliament.
"I express, on behalf of the people of India, our condolences to the people of Canada for the loss of their soldiers and our solidarity with them at this difficult moment."
Modi described Canada as "one of India's strongest partners and we will continue to strengthen our cooperation in combating terrorism and other crimes for a safer future for our people".
Parliament Hill in Ottawa came under attack Wednesday after a gunman shot dead a soldier standing guard at the National War Memorial, a day after Canada sent an air fleet to battle terrorists in Iraq and Syria.
About 30 to 50 shots were fired inside parliament and a gunman was confirmed dead, shot by security personnel.
Immediately after the attack, Modi said it was an "extremely disturbing" incident and added: "I pray for everyone's safety."