Military judge Colonel Theodore Dixon also levied a life sentence with parole that would be implemented if Hunsaker violates the terms of his plea agreement, which requires him to cooperate with prosecutors bringing cases against other soldiers accused in the crime.
Hunsaker was one of four soldiers charged in the killings that followed a May 9 raid at the al-Muthana chemical complex near Samarra, about 100 kilometres north of Baghdad.
Hunsaker's family members flooded the courtroom and wept when the sentencing was read Thursday afternoon. They declined to speak to the media.
In testimony during his court-martial, Hunsaker said he took "careful aim" at the detainees and tried to make it as "professional" as possible. He said he shot two detainees in the chest and head.
As part of a plea agreement, charges that Hunsaker had threatened another soldier's life if he told authorities of the killings were dropped.
The soldiers originally told investigators that they shot detainees because they were attempting to flee and that commanders told them to kill all military-age males - a story they now say they made up .
Details of the plea agreement were to be announced later Thursday. Three other soldiers were charged in the case.
During Thursday's hearing, Hunsaker recounted in testimony a meeting with his squad leader during which he said a plan to kill detainees in their custody was discussed. Hunsaker said Girouard gave the order.
"He told us to cut the zip ties, tell them to run and shoot them. I went out and did just that," he said.
The case is one of two involving soldiers from the 101st Airborne Division accused of killing Iraqis during a deployment to Iraq that ended in September.