The American soldier accused of killing 16 Afghan civilians, many of them women and children who were asleep in their villages, pleaded guilty to murder Wednesday and acknowledged to a judge there was “not a good reason in this world” for his actions.

Staff Sgt. Robert Bales’ plea ensures he will avoid the death penalty for the middle-of-the night slayings that so inflamed tensions with the Afghan population that the American military suspended combat operations.

Prosecutors say Bales slipped away before dawn on March 11, 2012, from his base in Kandahar Province. Armed with a 9 mm pistol and an M-4 rifle equipped with a grenade launcher, he attacked a village of mud-walled compounds called Alkozai, then returned and woke up a fellow soldier to tell him about it.

The soldier didn’t believe Bales and went back to sleep. Bales then left to attack a second village known as Najiban.

A jury will decide in August whether the soldier is sentenced to life with or without the possibility of parole.

Wednesday’s proceedings at Joint Base Lewis-McChord, south of Seattle, marked the first time Bales provided a public account of the massacre.

For each charge, the judge asked him a series of questions to assess the validity of his plea. Did he believe he had legal justification to kill the victims? Was he acting in self-defense? Did anyone force or coerce him to commit the murders?

For each, Bales answered, “No, sir.”

In a clear, steady voice, Bales also read from a statement.

“This act was without legal justification, sir,” the 39-year-old infantryman said while seated at a defense table, his hands folded in front of him.

At one point, the judge, Col. Jeffery Nance, asked Bales why he killed the villagers.

Bales responded: “Sir, as far as why — I’ve asked that question a million times since then. There’s not a good reason in this world for why I did the horrible things I did.”

One of the prosecutors, Lt. Col. Jay Morse, raised concerns during the hearing that the soldier’s testimony contradicted what he earlier acknowledged in a signed “stipulation of facts” from that night.

Bales testified Wednesday that he made the decision to kill each victim when he raised his gun and pointed it. But in the stipulation, Bales said he struggled with a woman before killing her and “after the tussle” decided to “murder anyone that he saw.”

The judge questioned Bales about it, and Bales confirmed that he decided to kill everyone after struggling with the woman.

Nance also questioned Bales about some corpses that had been set on fire. Bales said he didn’t remember burning the bodies, but he recalled a kerosene lantern being in one of the rooms and a fire and having matches in his pocket when he returned to the remote base, Camp Belambay.

Pressed by the judge on whether he set the bodies on fire with the lantern, Bales replied, “It’s the only thing that makes sense, sir.’”

Earlier, defense attorney Emma Scanlan entered Bales’ pleas on his behalf. She entered one not guilty plea, to a charge that he impeded the investigation by breaking his laptop after he was taken into custody. That charge was later dropped, after the judge accepted the guilty plea.

Given Bales’ prior deployments and apparent PTSD, military law experts had suggested that a jury was unlikely to sentence him to death. Defense attorney John Henry Browne had sought to place blame with the military for sending Bales back to war in the first place.

Bales and his defense team wanted the death penalty off the table. Prosecutors were able to secure a premeditated murder conviction, which might have been difficult to obtain at trial.