A Canadian soldier standing guard at a war memorial in the country's capital was shot dead today, and gunfire then erupted inside Parliament, authorities said.
One gunman was killed, and police said they were hunting for as many as two others.
The bloodshed immediately raised the spectre of a co-ordinated terrorist attack, with Canada already on alert because of a deadly hit-and-run earlier in the week against two Canadian soldiers by a man who police say was fired up with radical Muslim fervour.
Witnesses said the soldier was gunned down at point-blank range by a man carrying a rifle and dressed all in black, with a scarf over his face. They said the gunman then ran off and entered Parliament, a few hundred yards away, where dozens of shots soon rang out.
People fled the complex by scrambling down scaffolding erected for renovations, while others took cover inside as police with rifles and body armour took up positions outside and cordoned off the normally bustling streets around Parliament.
Police gave no details on how the gunman died. But on Twitter, Member of Parliament Craig Scott credited Parliament sergeant-at-arms Kevin Vickers with shooting the attacker just outside the MPs' caucus rooms.
Ottawa police spokesman Chuck Benoit said two or three gunmen were believed to be involved in the attacks. Gilles Michaud, assistant commissioner of the Royal Canadian Mounted Police, called it a "dynamic, unfolding situation".
Ottawa Hospital said it had received two patients, both said to be in a stable condition, in addition to the soldier.
Tony Zobl, 35, said he witnessed the soldier being gunned down from his fourth-floor window directly above the National War Memorial, a 70ft (21m), arched granite cenotaph, or tomb, with bronze sculptures commemorating the First World War.
"I looked out the window and saw a shooter, a man dressed all in black with a kerchief over his nose and mouth and something over his head as well, holding a rifle and shooting an honour guard in front of the cenotaph point-blank, twice," Mr Zobl told the Canadian Press news agency.
"The honour guard dropped to the ground, and the shooter kind of raised his arms in triumph, holding the rifle."
Mr Zobl said the gunman then ran up the street towards Parliament Hill.
Cabinet minister Tony Clement tweeted that at least 30 shots were heard inside Parliament, where Conservative and Liberal MPs were holding their weekly caucus meetings.
"I'm safe locked in a office awaiting security," Kyle Seeback, another Member of Parliament, tweeted.
A spokesman for Prime Minister Stephen Harper said he was safe and had left Parliament Hill. The US Embassy in Ottawa was locked down as a precaution.
Officials also cancelled two events in Toronto honouring Pakistani teenager and Nobel laureate Malala Yousafzai, including one in which she was supposed to receive honorary Canadian citizenship. The teenager was shot in the head by a Taliban gunman in 2012 for calling for schooling for girls.
US President Barack Obama condemned the attacks as "outrageous" and spoke by telephone with Mr Harper, offering to help and reassuring him of the American people's solidarity with Canada.
The attack came two days after a recent convert to Islam killed one Canadian soldier and injured another with his car before being shot dead by police. The killer had been on the radar of federal investigators, who feared he had jihadist ambitions and seized his passport when he tried to travel to Turkey.
Canada had raised its domestic terror threat level from low to medium yesterday because of "an increase in general chatter from radical Islamist organisations", said Jean-Christophe de Le Rue, a spokesman for the public safety minister.
In the hours after today's attack, police warned people in central Ottawa to stay away from windows and rooftops.
Scott Walsh, 21, a construction worker working in a manhole right in front of Parliament Hill, said he heard the shots at the war memorial.
"We're in construction and we're used to loud bangs. When people started screaming and running, that's when I clued, and I saw this guy running" with a gun, he said. "It was intense. I didn't think it was real."
He said the gunman had long black hair with a scarf covering the lower half of his face.