Staff Sergeant Robert Bales, of the 2nd Battalion, 3rd Infantry Regiment, on Friday was also accused of six counts of assault and attempted murder in the Panjwai district of Kandahar province earlier this month.
The killings -- mostly of women and children -- are believed to be the deadliest war crime by a NATO soldier during the decade-long conflict and have tested Washington and Kabul's already tense relationship to the limit.
Responding to the charges, a spokesman for Afghan President Hamid Karzai said: "We want justice and we want it as soon as possible," while a spokesman for Bales's home base said it will likely be 18-24 months until any trial.
In a statement, the US military said the maximum punishment for premeditated murder is "a dishonourable discharge from the armed forces, reduction to the lowest enlisted grade, total forfeiture of pay and allowances, and death."
The mandatory minimum sentence for the killings of nine children, four women and four men, and attacks on four children, one man and one woman is life imprisonment with the possibility of parole, it added.
Bales, 38, is currently being held at Fort Leavenworth in Kansas, and a US forces spokesman said it was "more than likely" the trial would be held in the United States, although the decision would be made later in the process.
But furious relatives of the victims have demanded proceedings take place in Afghanistan.
Haji Samad, an elder who lost 11 members of his family, said: "He committed the crime in Afghanistan. Why he is going to be prosecuted in the US?"
Bales allegedly walked off his base in the southern province of Kandahar under cover of darkness March 11 and killed 17 people in two nearby villages, burning some of their bodies before returning to his base and surrendering.
The massacre has deepened a sense of crisis in the NATO mission and renewed questions about the effect of protracted ground wars on America's stretched force, becoming just the latest in a series of damaging setbacks since January.
The burning of Korans in mid-February triggered deadly anti-US protests, there has been a surge in "insider" attacks on NATO troops by Afghan forces and a video emerged of US Marines urinating on bloodied Taliban corpses.
The next stage in the Bales case will see him appear before a so-called Article 32 hearing, which will decide whether to proceed with a court-martial -- but the military has almost four months in which to hold it.
His lawyer John Henry Browne, who visited his client for the first time this week, has said Bales suffered from amnesia, and that he could pursue the case on the grounds of "diminished capacity" due to an emotional breakdown.
But Haji Noor Mohammad, who lost his grandfather, grandmother, a sister and a cousin told AFP: "If he is truly crazy and had lost his memory then why he is appointed as a US soldier? Why is he not admitted to the hospital instead?"
A decorated veteran who served three times in Iraq before deploying to Afghanistan in December, Bales suffered a traumatic brain injury during a road accident in Iraq.
But reports have surfaced in the US media of past brushes with law, notably involving alcohol.
Court records show a 1998 citation in Florida for having alcohol on a beach, a 2002 charge involving a drunken assault at a casino, a drunk driving arrest in 2005 and an alcohol-infused brawl in 2008, the Los Angeles Times reported.
Questions have been raised over whether Bales was drinking before the massacre -- Browne has admitted that, despite a military alcohol ban, his client "had a couple sips of something but he didn't have a full drink."
Bales and his wife were reportedly also facing financial problems, with news reports saying he owes $1.5 million from a 2003 arbitration ruling in which he was found guilty of securities fraud.
The sergeant's monthly pay is listed as $3,243.30 on the charge sheet released by Joint Base Lewis-McChord, south of Seattle, where he was based and where his family was moved to after the incident, for their protection.
The charge sheet had the names of the victims blanked out, and listed the injuries sustained by the survivors, including gunshots to the neck, head, chest, thigh and groin, according to the charge sheet.
A Fort Lewis-McChord spokesman said the trial is likely to be either there or at the Kansas base, and will likely not be held for at least 18 months.
"It's going to be a long process -- normally between 18 to 24 months before it actually would go to trial, if it goes to trial," spokesman Chris Ophardt told AFP.