But Judge Lamberth took exception to that, saying he had served a tour in the Vietnam War and had been in many dangerous situations. Nevertheless, he said troops must rely on each other and obey the rules to ensure that innocent civilians were not unnecessarily harmed. In the case of the Nisour Square massacre, he said, the evidence made clear that there had been no incoming fire against the convoy and that “there was no necessity” to shoot Mr. Al Rubia’y.

One security contractor involved in the episode, Jeremy Ridgeway, pleaded guilty to manslaughter and cooperated with prosecutors. But the cases against others involved in the shooting proved difficult.

A federal judge in 2009 threw out the indictment of five contractors, citing a “reckless violation of the defendants’ constitutional rights.” The judge said that investigators, prosecutors and government witnesses had inappropriately relied on statements that the guards had been compelled to make in debriefings by the State Department shortly after the shootings.

A new prosecution team was able to revive a case against four of them, and in a trial in 2014, a jury found Mr. Slatten guilty of murder and convicted three colleagues — Dustin L. Heard, Evan S. Liberty and Paul A. Slough — of voluntary manslaughter and using a machine gun to carry out a violent crime. Mr. Slatten was given life in prison, and the others were sentenced to 30 years in prison.

But charging the defendants with machine-gun offenses, a crime not meant for battlefield situations, was controversial, even in the Justice Department. In 2017, a federal appeals court ruled that the machine-gun charges and offenses were “grossly disproportionate to their culpability for using government-issued weapons in a war zone,” and said that Mr. Slatten should not have been tried alongside the other three.

The court ordered a do-over trial for Mr. Slatten and vacated the sentences of the three colleagues, deferring their resentencings until after his case is concluded. But in 2018, the first attempt to retry him ended in a mistrial, with the jury deadlocked after his defense lawyer stressed testimony from another contractor who testified that he, not Mr. Slatten, shot first. But prosecutors tried a third time, and won another guilty verdict against Mr. Slatten for first-degree murder.

Denouncing that outcome on Wednesday, Mr. Slatten also noted that prosecutors had offered to let him plead guilty to a manslaughter charge, but that he rejected the offer because, he said, he was innocent.

Judge Lamberth suggested that that level of charge might have been appropriate, but said that Mr. Slatten had decided to take the “all or nothing” gamble of going to trial on a more serious murder charge, and “got what he gambled for.”