Media playback is unsupported on your device Media caption Fort Hood victim Sgt Alonzo Lunsford says "let the sword of justice swing"

A former US Army psychiatrist who killed 13 soldiers at a base in Texas in 2009 has admitted in court he was the gunman and apologised for "any mistakes", as his court martial opened.

But Maj Nidal Hasan told the jury at Fort Hood, Texas, that the evidence told only one side of the story.

The 42-year-old says he was protecting Muslims and the Taliban in Afghanistan.

If convicted on 13 counts of murder and 32 counts of attempted murder, the US-born Muslim could face execution.

"The evidence will clearly show that I am the shooter," Maj Hasan, who is acting as his own lawyer, told the jury of 13 military officers as the trial began on Tuesday.

"We are imperfect Muslims trying to establish the perfect religion," added the accused, who uses a wheelchair after being paralysed when he was shot during the attack.

He declined to cross-examine any of the witnesses wounded in the assault.

'Careful preparations'

The killings on 5 November 2009 are the deadliest ever non-combat attack on an American military base.

During the prosecution's opening statements, Col Steve Henricks said Maj Hasan had deliberately targeted "unarmed, unsuspecting and defenceless soldiers" when he opened fire, and planned to "kill as many soldiers as he could".

Media playback is unsupported on your device Media caption The BBC's Nick Bryant says the court "looks more like a bunker"

He said the accused had prepared carefully for the attack, visiting a target practice range, buying a gun, and stuffing paper towels into his trouser pockets to muffle noise from the weapons before he opened fire.

"All those fully loaded magazines do not clink, do not move, do not give him away," Col Henricks told the jury. "He sits among the soldiers he's about to kill with his head down."

The court heard that Maj Hasan had first tried to clear the area of civilians, even walking over to a clerk to tell her a supervisor needed her elsewhere in the building.

He then climbed on to a desk, shouted an Islamic benediction, and opened fire with two handguns, witnesses said.

'Dead men don't sweat'

According to the prosecution, he fired 146 bullets.

They've got another thing coming if they think they are going to deploy me Maj Nidal Hasan, Fort Hood shooter

The attack took place in a crowded medical building where deploying soldiers were awaiting check-ups and vaccines.

Staff Sgt Alonzo Lunsford, who was shot seven times during the attack, testified how he had played dead.

Then he worried that the gunman might notice he was perspiring, as "dead men don't sweat".

Sgt Lunsford said he decided to flee and found an exit crammed with other soldiers trying to make their escape, too.

Maj Hasan was himself about to be deployed to Afghanistan at the time of the assault.

But the court heard that he had told a base doctor: "They've got another thing coming if they think they are going to deploy me."

The government has said Maj Hasan sent more than a dozen emails starting in December 2008 to Anwar al-Awlaki, a radical US-born Islamic cleric killed by a drone strike in Yemen in 2011.

Maj Hasan wanted to plead guilty to murder and attempted murder, but military rules forbid guilty pleas in death-penalty cases.

There is outrage in the US that he is still receiving his salary.

He has reportedly received wages totalling nearly $300,000 (£200,000) while awaiting trial.