JOINT BASE LEWIS-McCHORD, Wash. — Staff Sgt. Robert Bales, who pleaded guilty to slaughtering 16 Afghan civilians inside their homes, will spend the rest of his life in prison, a military jury decided on Friday.

The decision came after three days of wrenching testimony that painted a moment-by-moment, bullet-by-bullet account of one of the worst atrocities of the United States’ long war in Afghanistan.

The six-member military jury considering Sergeant Bales’s fate had two options: sentence him to life in prison with no possibility of parole, or allow him a chance at freedom after about 20 years behind bars. His guilty plea in June removed the death penalty from the table.

In pressing for mercy, the defense team said Sergeant Bales had been a good soldier, a loving father and a stand-up friend before snapping after four combat deployments to Iraq and Afghanistan. But prosecutors said he was a man frustrated with his career and family, easy to anger, whose rage erupted at the end of his M-4 rifle.