The American soldier accused of shooting 16 Afghan villagers in a pre-dawn killing rampage has been flown out of Afghanistan, a U.S. military official says.

The soldier was taken out of Afghanistan "based on a legal recommendation," said navy Capt. John Kirby, a Pentagon spokesman. "We do not have appropriate detention facilities in Afghanistan," he said, explaining that he was referring to a facility for a U.S. service member "in this kind of case."

The soldier has not yet been charged.

Afghan lawmakers had demanded that the soldier be publicly tried in Afghanistan to show that he was being brought to justice, calling on President Hamid Karzai to suspend all talks with the United States about a continuing military presence here until that happens.

Many fear a misstep by the U.S. military in handling the case could ignite a firestorm in Afghanistan that would shatter already tense relations.

The alliance between Afghanistan and the U.S. military already appeared near the breaking point last month when the burning of Qur'ans in a garbage pit at a U.S. base sparked protests and retaliatory attacks that killed more than 30 people, including six American soldiers. In recent days the two countries made headway toward an agreement governing a long-term American presence in the country, but the shootings in Kandahar province on Sunday have called all such negotiations into question.

Panetta visits

The decision to move the soldier came as U.S. Defence Secretary Leon Panetta, in a series of meetings with troops and Afghan leaders Wednesday, said the U.S. must never lose sight of its mission in the war, despite recent violence including what appeared to be an attempted attack near the runway of a military base where he was about to land.

It wasn't clear whether it was an attempt to attack the defence chief, whose travel to southern Afghanistan was not made public before he arrived. Panetta was informed of the incident after landing.

 "We will not allow individual incidents to undermine our resolve to that mission," he told Marines at Camp Leatherneck. "We will be tested. We will be challenged — we'll be challenged by our enemy, we'll be challenged by ourselves, we'll be challenged by the hell of war itself. But none of that, none of that, must ever deter us from the mission that we must achieve."

According to Pentagon spokesman Navy Capt. John Kirby, an Afghan stole a vehicle at a British airfield and drove it to a runway, crashing into a ditch about the same time that Panetta's aircraft was landing. He said the pickup truck drove at high speed onto the ramp where Panetta's plane was intended to stop.

No one in Panetta's party was injured.

Gradual withdrawal

Panetta's trip to the warfront, which included three stops in the south, was planned months ago, long before the weekend shooting rampage. Everywhere he went, including a meeting with provincial leaders, Panetta referred obliquely to the massacre but didn't go into it in detail. Instead, he talked about the need for the Afghan and coalition forces to keep working together to help transition security of the country to the Afghan forces.

Panetta and other U.S. officials say the shooting rampage should not derail the U.S. and NATO strategy of a gradual withdrawal of troops by the end of 2014. But it has further soured relations with war-weary Afghans, jeopardizing the U.S. strategy of working closely with Afghan forces on the transition.

Panetta met with several Afghan provincial leaders and told them the primary mission is to prepare for the transition to Afghan security control. He acknowledged there will continue to be challenges from the enemy as well as issues between U.S. and Afghan allies, but he said everyone must remain committed.   

The military has detained an army staff sergeant in connection with Sunday's massacre. An Afghan official said Tuesday that surveillance video showed the sergeant walking up to his base and raising his arms in surrender. The official, who spoke anonymously to discuss a private briefing, said U.S. authorities showed Afghan authorities the surveillance video to prove that only one perpetrator was involved in the Sunday shootings.   

A delegation investigating the shootings was meeting in the southern city of Kandahar on Wednesday when a bomb hidden in a motorcycle exploded about 600 metres away. The blast killed one Afghan intelligence official and wounded three other people, but the delegation members were unharmed.

Panetta's two-day visit is scheduled to include meetings with Karzai, Afghan defence officials and provincial leaders, as well as routine discussions with his commanders on the ground. The sessions are likely to touch on America's planned withdrawal of about 22,000 troops by fall, including as many as 10,000 Marines from Helmand Province.