The US soldier accused of killing 16 Afghans could be executed if convicted, the Pentagon chief said, as President Barack Obama warned a war-weary public against a rushed exit from Afghanistan.

Defense Secretary Leon Panetta told reporters aboard his plane en route to Kyrgyzstan that the shooting suspect would be brought to justice under the US military legal code, which allows for the death penalty in some cases.

The US army sergeant, who was on his first tour of duty in Afghanistan after serving three tours in Iraq, left his base in Kandahar province before dawn Sunday and went on a murderous rampage, Afghan and US officials say.

He is accused of breaking into village homes and opening fire, killing 16 people including women and children, in an incident that has imperilled Afghan-US relations anew after the burning of Korans at a US military base.

"Then at some point after that (he) came back to the forward operating base and basically turned himself in," Panetta said late Monday. "Told individuals what happened."

The Pentagon chief was asked if the suspect could be sentenced to death. "My understanding is in these instances that could be a consideration," he said.

Afghan President Hamid Karzai has described the shootings as "unforgivable," and the Afghan parliament declared that "people are running out of patience" over the behavior of the 130,000 US-led NATO troops deployed in the country.

The Taliban, leading a 10-year insurgency against the foreign troops and Karzai's government, threatened to take revenge against "sick-minded American savages."

The parliament on Monday demanded that US officials "punish the culprits and try them in a public trial before the people of Afghanistan," then closed for the day in protest.

But the Pentagon made clear that it would prosecute the soldier. He has not been named, but officials said he is in his 30s and that the investigation will look into whether he may have been suffering from mental trauma.

The massacre is the latest serious test of the US-Afghan alliance as the two countries pursue difficult talks on securing a strategic pact to govern their partnership once foreign combat troops leave Afghanistan in 2014.

One major sticking point is the Karzai government's refusal so far to grant legal immunity to US troops -- the same issue that scuppered a US strategic pact with Iraq.

In Washington, Obama warned the US public against "a rush for the exits" from Afghanistan, after a new poll at the weekend said most Americans believe the war in Afghanistan is not worth the cost and want an early pullout.

"It's important for us to make sure that we get out in a responsible way, so that we don't end up having to go back in," Obama said in an interview with CBS station KDKA in Pittsburgh.

"But what we don't want to do, is to do it in a way that is just a rush for the exits," he said, stressing the need for an orderly withdrawal to get US personnel and equipment out.

Obama added: "We have got to make sure that the Afghans can protect their borders to prevent Al-Qaeda coming back."

But in a separate interview with Denver CBS affiliate KCNC, Obama said it was "important for us just to make sure that we are not ... in Afghanistan longer than we need to be."

The commander of US-led forces in Afghanistan, US General John Allen, told CNN the killings appeared to have been an "isolated act."

An Afghan soldier detected the absence of the US sergeant and immediately reported it, Allen said.

"We put together a search party right away and it was as that search party was forming that we began to have indications of the outcome of his departure."

The weekend incident is the latest in a series of actions by troops that has provoked outrage in Afghanistan, and comes weeks after the burning of the Korans sparked riots that killed 40 people and plunged ties to an all-time low.

Braced for the worst, the US embassy urged its citizens in Afghanistan to take extra precautions.

But there were no reports of protests by late Monday, and Kandahar community leaders appealed against any violence.

Karzai spoke by telephone with relatives of those killed, including Rafihullah, a 15-year-old boy wounded in the leg who told the president the soldier had torn the dresses of the women in the house and insulted them.

"He came to my uncle's home, he was running after women, he was tearing their dresses, insulting them," Rafihullah said on an audiotape of the conversation heard by AFP.

"He killed my uncle and killed our servant and killed my grandma, he shot dead my uncle's son, his daughter," the boy said.