A caped figure captured on surveillance video came running out of the darkness to the edge of a remote Army outpost in southern Afghanistan. Blood was smeared on his face, prosecutors said, and soaked into his clothes.
About two kilometres away, 16 Afghans, including nine children, were dead, some of their bodies on fire in two villages.
As fellow soldiers stopped him at the base's gate, Staff Sergeant Robert Bales was incredulous, prosecutors said.
Then, as he was taken into custody, Bales said: "I thought I was doing the right thing".
The details, from a prosecutor as well as Bales' comrades, emerged on Monday as a preliminary hearing in his case opened, offering the clearest picture yet of one of the worst atrocities of the Iraq and Afghanistan wars.
The attack on March 11 prompted the US to halt combat operations for days in the face of protests, and it was a month before military investigators could reach the crime scenes.
Bales, 39, faces 16 counts of premeditated murder and six counts of attempted murder. The hearing could last up to two weeks and will help determine whether the case goes to a court martial.
The defence did not give an opening statement.
Bales has not entered a plea. His lawyers have not discussed the evidence, but say Bales has post-traumatic stress disorder and suffered a concussive head injury during a prior deployment to Iraq.
The father of two from Lake Tapps, Washington, wore green fatigues and sat beside one of his civilian lawyers as an investigating officer read the charges against him and informed him of his rights.
When asked if he understood them, Bales said, "Sir, yes, sir".
Bales spent the March night before the raids at Camp Belambay, watching Man On Fire, a fictional account of a former CIA operative on a revenge spree, with his fellow soldiers, said Lieutenant Colonel Jay Morse, the prosecutor.
He seemed normal as they shared whiskey, discussed Bales' anxiety over whether he'd get a promotion and talked about another soldier who lost his leg a week earlier in a roadside bomb attack, Corporal David Godwin testified.
Shortly before leaving the base, Bales told a Special Forces soldier that he was unhappy with his family life and that the troops should have been quicker to retaliate for the March 5 bomb attack, Morse said.
"At all times, he had a clear understanding of what he was doing and what he had done," said Morse, who described Bales as lucid and responsive.
Bales is accused of slipping away from the remote outpost with an M-4 rifle outfitted with a grenade launcher to attack the villages of Balandi and Alkozai, in a dangerous district.
Morse said Bales broke the killings into two episodes. Dressed in a T-shirt, Bales walked first to one village, returned to the base and then slipped away again to carry out the second attack.
Between the episodes, Bales told a colleague about shooting people at one of the villages, Morse said.
The soldier apparently took it as a bad joke and responded: "Quit messing around".
Prosecutors played for the first time the video captured by a surveillance blimp that showed the caped figure running toward the base, then stopping and dropping his weapons as he was confronted. There was no audio.
It wasn't immediately clear from where Bales got the cape.
As he stood outside the base, Godwin testified, Bales had asked him and another soldier: "Did you rat me out? Did you rat me out?"
Part of the hearing will be held overnight to allow video testimony from witnesses, including an estimated 10 to 15 Afghans, in Afghanistan.
Bales' lawyer, John Henry Browne, said the hearing will give the defence a chance to see what the military can prove. He said they are expecting a court martial.
The Ohio native joined the Army in late 2001 - after the 9/11 attacks - as his career as a stockbroker imploded, including an arbitrator's $US1.5 million ($A1.45 million) fraud judgment against him and his former company.
Bales was serving his fourth combat tour after three stints in Iraq and his arrest prompted a national discussion about the stresses that soldiers face from multiple deployments.
His lawyers have said Bales remembers little or nothing from around the time of the attacks.
Emma Scanlan, one of his lawyers, declined to say to what extent the lawyers hope to elicit testimony that could be used to support a mental-health defence. Bales himself will not make any statements.
She said the Army had only recently turned over a preliminary DNA trace evidence report from the crime scenes, but defence experts have not had time to review it.