Image caption Morlock appeared before a court martial at a military base in Washington state

A US soldier accused of being a part of a rogue squad that killed unarmed Afghan men has been sentenced to 24 years in prison.

Specialist Jeremy Morlock, 22, pleaded guilty to three counts of murder and other crimes.

Under a plea deal he is expected to testify against four comrades also to be tried over the killings last year in Kandahar province.

"The plan was to kill people," Morlock told a military judge on Wednesday.

The judge, Lt Col Kwasi Hawks, had asked whether the accused were shooting to kill or meant only to scare the Afghan civilians.

Lt Col Hawks said he had intended to sentence Morlock to life in prison with the possibility of parole but had been bound by a plea bargain under which Morlock would be sentenced to a maximum of 24 years in prison in return for testifying against his comrades.

Morlock, 22, is part of the 5th Stryker Brigade based at Joint Base Lewis-McChord in the US state of Washington, which deployed to Afghanistan last year and saw heavy fighting around Kandahar.

'Everyone knew'

The killings took place between January and May last year.

At the court martial at the base in Washington on Wednesday, Morlock pleaded guilty to three counts of murder and one count each of illegal drug use, conspiracy and obstructing justice.

He told Lt Col Hawks that he and others had begun plotting the killings in late 2009, and that they had conspired to plant weapons on the corpses to make the killings appear justified.

"Did everybody know, 'We're killing people who are completely innocent'?" Lt Col Hawks asked.

"Generally, yes, sir, everyone knew," Morlock replied.

He said the murder plot was led by the unit's leader, Staff Sgt Calvin Gibbs, who is also charged in the killings but who has said they were justified.

The proceedings come two days after German magazine Der Spiegel published photographs showing US soldiers grinning over the corpses of Afghan civilians they had allegedly killed.

The magazine identified Morlock as one of the soldiers posing.

'Reprehensible' conduct

In addition to Staff Sgt Gibbs, charged in the murders are Pte First Class Andrew Holmes, Spc Michael Wagnon and Spc Adam Winfield.

Other soldiers are accused of dismembering the victims and collecting body parts.

The photos published by Der Spiegel were said to be among many seized by US Army investigators.

On Tuesday, US Gen David Petraeus, the commander of Nato forces in Afghanistan, condemned the soldiers' conduct.

"Those are very reprehensible," he said. "These are unacceptable actions that are depicted in those photos."