A gunman shot and killed a soldier guarding the National War Memorial in the Canadian capital Ottawa and was then killed when he entered nearby parliament buildings chased by police.

Officials named the dead gunman as Canadian-born Michael Zehaf-Bibeau.

Canadian police said they could not "at this point" confirm whether the man who shot dead the soldier, who was guarding the National War Memorial in central Ottawa, was the same person who shortly afterwards attacked the parliament building.

The dead soldier was named locally as Nathan Cirillo.

Police raced to seal off the parliament building and the office of Canadian Prime Minister Stephen Harper, pushing reporters and bystanders further back and blocking roads with squad cars. 

Mr Harper left the area of the shooting and was "safe", his spokesman Jason MacDonald said.

Veterans Affairs Minister Julian Fantino, a former policeman, said parliament's head of security, Sergeant-at-Arms Kevin Vickers, shot dead the suspected gunman.
              
"All the details are not in, but the sergeant-at-arms, a former Mountie, is the one that engaged the gunman, or one of them at least, and stopped this," Mr Fantino said.
              
Canadian cabinet minister Jason Kenney said a guard in parliament buildings had also been wounded in the incident.

Many shots were fired just outside the room where Mr Harper was addressing a meeting of legislators.

"PM (Harper) was addressing caucus, then a huge boom, followed by rat-a-tat shots. We all scattered. It was clearly right outside our caucus door," Treasury Board Minister Tony Clement said.

A spokesman for Mr Harper said: "While the prime minister stated that facts are still being gathered, he condemned this despicable attack."

The Irish Embassy in Ottawa is within the lockdown zone.

The staff of embassy have been allowed to leave the building and go home

The Ambassador of Ireland to Canada, Ray Bassett, is out of Ottawa on official business.

It is also unclear whether there was any connection to an attack on Monday when an Islamic convert ran down two Canadian soldiers with his car, killing one, near Montreal, before being shot dead by police in the first fatal attack on Canadian soil tied to Islamic militants.

People in Ottawa city centre were told to stay away from windows and off roofs due to an "ongoing police incident," the Royal Canadian Mounted Police cautioned in a statement.

One witness, Marc-Andre Viau, said he saw a man run into a caucus meeting the parliament, chased by police who yelled "take cover".

That was followed by "10, 15, maybe 20 shots," possibly from an automatic weapon, he said.

The United States has offered its assistance and US President Barack Obama spoke earlier to the Canadian prime minister by phone.

Centre Block is the main building at Parliament Hill, a sprawling complex of buildings and open space in downtown Ottawa.

It contains the House of Commons and Senate chambers as well as the offices of some members of parliament, senators, and senior administration for both legislative houses.

A Globe and Mail reporter in Centre Block on Parliament Hill tweeted that the building was under lockdown after "at least one shooter burst in and opened fire".

One member of parliament, Mark Strahl, tweeted from inside parliament: "Very tense situation in Ottawa this morning. Multiple gun shots fired outside of our caucus room. I am safe and in lockdown. Unbelievable."

Army bases across Canada were closed to the public because of the incident.

The incident came a day after 25-year-old Martin Couture-Rouleau ran over a soldier, killing him before being shot dead by police as he emerged from his wrecked car wielding a knife.

The government branded this a terrorist attack by a suspected Islamist, amid reports that Couture-Rouleau was a supporter of the so-called Islamic State, the militant group operating in Iraq and Syria. 

If the driver's alleged jihadist sympathies are confirmed, it would be Canada's first ever Islamist attack, although authorities have warned they are tracking 90 suspected extremists in the country.

Authorities raised the security threat level from low to medium after the incident, which came as Canadian jets were to join the US-led air armada bombarding Islamist militants in Iraq.  

"This level means that intelligence has indicated that an individual or group within Canada or abroad has the intent and capability to commit an act of terrorism," the Public Safety Ministry said.

It happened the day that Pakistani peace campaigner Malala Yousafzai was to receive her honourary Canadian citizenship.

However, the event was cancelled because of the shootings.