Media playback is unsupported on your device Media caption Lt Gen Mark Milley describes the final moments before the gunman shot himself

A soldier shot dead three colleagues and injured 16 others at the US Army's Fort Hood base in Texas before killing himself, the military says.

US media named the suspect as Ivan Lopez, 34, although his identity has not been officially confirmed.

The gunman had served in Iraq and had mental health problems, officials said.

President Barack Obama said he was "heartbroken" over the attack. A gun rampage at the same base in 2009 left 13 soldiers dead and 32 wounded.

Maj Nidal Hasan was sentenced to death for that attack.

'Sacrifice'

US military spokesman Lt Gen Mark Milley told reporters that there was so far no indication that Wednesday's shootings were related to terrorism.

Media playback is unsupported on your device Media caption Barack Obama said he was "heartbroken" when he heard the news

Media playback is unsupported on your device Media caption Killeen Mayor Daniel Corbin says the community 'feels helpless'

He said the suspect had not been injured when he served in Iraq in 2011, but was being assessed to see if he had post-traumatic stress disorder.

The gunman was being treated for depression and anxiety, Gen Milley added.

The general said that it was not clear if the attack was premeditated and those wounded and killed were all members of the military.

Image copyright Reuters Image caption Luci Hamlin and her husband Specialist Timothy Hamlin wait to be allowed back into the camp

Image copyright AP Image caption A 2009 satellite image of Fort Hood following the earlier shooting incident

Image copyright Reuters Image caption The all clear has now been sounded

Image copyright Reuters Image caption The 2009 rampage left 13 soldiers dead

The soldier drove to two buildings on the base and opened fire before he was stopped by military police, in an incident that lasted between 15 and 20 minutes.

Fort Hood Created in 1942 out of 108,000 acres of Texas farming land and initially known as Camp Hood

Home to almost 95,000 troops at height of World War Two

Eight years after officially opened, Camp Hood became permanent military installation and was renamed Fort Hood

One of the largest military installations in the world, with nearly 65,000 soldiers

Divided into three sections: the main cantonment, West Fort Hood, and North Fort Hood.

Units from the base have been deployed to Afghanistan, Iraq and US hurricane relief operations

He then shot himself in the head with a .45-calibre semi-automatic pistol, Gen Milley said.

Officials say the weapon had been bought in a local store. Firearms are largely banned at US Army bases, with few soldiers besides military police allowed to carry them.

Mr Obama told reporters in Chicago: "I want to just assure all of us we are going to get to the bottom of exactly what happened."

Mr Obama said Ford Hood had sacrificed so much for freedom.

"We know these families. We know their incredible service to our country and the sacrifices that they make. Obviously our thoughts and prayers... are with the entire community," he said.

Defence Secretary Chuck Hagel called the shooting a "terrible tragedy".

Daniel Corbin, mayor of nearby Killeen in Texas, told the BBC he felt nearly "indescribable" grief for those involved.

"We pray for them when they are deployed. We try to take care of their families and we're really close as a community to Fort Hood," he said. "You wish you could, you know, give some immediate help, but you can't."

Maj Hasan was sentenced to death last September over the 2009 rampage.

He claimed he opened fire at the army base to protect Taliban insurgents from US troops who were about to deploy to Afghanistan.

It was the deadliest attack on a domestic military installation in US history.