OTTAWA, Ontario (AP) — A gunman with a scarf over his face killed a soldier standing guard at Canada’s war memorial Wednesday, then stormed Parliament in an attack that rocked the building with the boom of gunfire and forced lawmakers to barricade themselves in meeting rooms. The gunman was shot to death by the ceremonial sergeant-at-arms.
Investigators offered little information about the gunman, identified as 32-year-old ex-convict Michael Zehaf-Bibeau, but Prime Minister Stephen Harper called the rampage the second deadly terrorist attack on Canadian soil in three days.
‘‘This week’s events are a grim reminder that Canada is not immune to the types of terrorist attacks we have seen elsewhere,’’ Harper said.
He added: ‘‘We will not be intimidated. Canada will never be intimidated.’’
Canada was already on alert at the time of the shooting rampage because of a deadly hit-and-run assault Monday against two Canadian soldiers by a man Harper described as an ‘‘ISIL-inspired terrorist.’’ ISIL is also known as Islamic State.
Witnesses said the soldier posted at the National War Memorial, identified as Cpl. Nathan Cirillo, was gunned down at point-blank range just before 10 a.m. by a man carrying a rifle and dressed all in black, his face half-covered.
The gunman appeared to raise his arms in triumph, then entered Parliament, a few hundred yards away, where dozens of shots soon rang out, according to witnesses.
People fled the complex by scrambling down scaffolding erected for renovations, while others took cover inside and barricaded doors with chairs as police with rifles and body armor took up positions outside and cordoned off the normally bustling streets around Parliament.
On Twitter, Canada’s justice minister and other government officials credited 58-year-old sergeant-at-arms Kevin Vickers with shooting the attacker just outside the MPs’ caucus rooms. Vickers serves a largely ceremonial role at the House of Commons, carrying a scepter and wearing rich green robes, white gloves and a tall imperial hat.
At least three people were treated for minor injuries.
In Washington, President Barack Obama condemned the shootings as ‘‘outrageous’’ and said: ‘‘We have to remain vigilant.’’ The U.S. Embassy in Ottawa was locked down as a precaution, and security was tightened at the Tomb of the Unknown Soldier at Arlington National Cemetery just outside Washington.
Police said in the initial hours after the shootings that as many as two other gunmen may have taken part. But as the day wore on, the cordon around Parliament was eased, employees were allowed to go home, and it appeared increasingly likely that the attack was the work of one person.
Court records show that a man with the same name and year of birth as the gunman was charged with robbery in Vancouver in 2011. He pleaded guilty to the lesser charge of uttering threats and was sentenced to a day in jail plus credit for the 66 days he had already served.
Tony Zobl said he witnessed the Canadian soldier being gunned down from his fourth-floor window directly above the National War Memorial, a 70-foot, arched granite cenotaph, or tomb, with bronze sculptures commemorating World War I.
‘‘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 honor guard in front of the cenotaph point-blank, twice,’’ Zobl told the Canadian Press news agency. ‘‘The honor guard dropped to the ground, and the shooter kind of raised his arms in triumph holding the rifle.’’
The Canadian Broadcasting Corp. had video of the gunman going to his car alone with his weapon after the shooting at the memorial. The car was later spotted parked in front of Parliament Hill, just down the block.
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.
The chief spokesman for Prime Minister Stephen Harper said Harper was safe and had left Parliament Hill.
‘‘I was just taking off my jacket to go into caucus. I hear this pop, pop, pop. Possibly 10 shots, don’t really know. Thought it was dynamite or construction rather than anything else,’’ said John McKay, a member of Parliament.
He said security guards then came rushing down the halls, herding them toward the back of the buildings.
‘‘And then we started talking to another woman and she was apparently inside the library of Parliament, saw the fellow, wearing a hoodie, carrying a gun,’’ McKay said, ‘‘and then the implications of this start to sink in.’’
The attack came two days after a recent convert to Islam killed one Canadian soldier and injured another with his car before being shot to death 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 Tuesday because of what it called ‘‘an increase in general chatter from radical Islamist organizations.’’
The Islamic State group has urged supporters to carry out attacks against Western countries, including Canada, that are fighting the militants in Iraq and Syria. Eight Canadian fighter jets left for the region on Tuesday.
Canadian Foreign Minister John Baird, in a telephone conversation with U.S. Secretary of State John Kerry, appeared to link the attack to Canada’s participation in the U.S.-led air campaign against the Islamic State group.
‘‘My message: ‘This is why we’re with you. This only makes our resolve stronger,'’’ Baird tweeted about his talk with Kerry.
After the shootings, officials canceled two events in Toronto honoring Pakistani teenager and Nobel laureate Malala Yousafzai, including one in which she was supposed to receive honorary Canadian citizenship. She was shot in the head by a Taliban gunman in 2012 for supporting schooling for girls.
Gillies reported from Toronto. Associated Press writer Benjamin Shingler also contributed to this report.
Correction: An earlier version of this story contained an Associated Press map that incorrectly identified the location of the Rideau Centre in Ottawa.