"I take full responsibility for my actions," he said. "Now I have to pay for my mistake."
The prisoners had been detained after repeated attacks on Mayo's unit, including a sniper attack in which one of his friends and a fellow sergeant were killed.
The defendant had been almost killed by an explosive device a few months earlier, and suffered a brain injury, Michael Waddington, his lawyer, said.
'Frustration and fear'
Captain David Nelson-Fischer, a witness for the defence, said the unit suffered from "frustration and fear" because of a high frequency of attacks on Mayo's small, highly exposed post in the West Rashid neighbourhood of Baghdad.
But Captain John Riesenberg, the army's trial counsel, said the defendant had "demonstrated a total lack of moral courage".
He had urged the judge to deliver a sentence that would "send a message to the army and to the world".
Mayo has agreed to testify at the forthcoming trial of Master Sergeant John Hatley, another US soldier identified by witnesses as having taken part in the murders in 2007.
In February, Sergeant Michael P. Leahy, an army medic, was sentenced to life in prison with the possibility of parole, while two other soldiers have been convicted of lesser crimes linked to the incident.