WASHINGTON — Three former Blackwater security contractors were sentenced on Thursday to roughly half of their original 30-year prison terms for the deadly 2007 shooting of unarmed Iraqi civilians in Baghdad’s Nisour Square, widely seen as one of the darkest moments of the Iraq war.

The three former contractors — Dustin L. Heard, Evan S. Liberty and Paul A. Slough — had been convicted in 2014 of multiple counts of manslaughter for their roles in the massacre. But in 2017, a federal appeals court vacated their sentences, saying the trial judge, Royce C. Lamberth of the Federal District Court for the District of Columbia, erred in invoking a law that requires 30-year sentences for such offenses that involve machine guns.

That law did not apply to the use of government-issued machine guns in a war zone, the court ruled. Prosecutors on Thursday nevertheless asked Judge Lamberth to resentence Mr. Slough to 30 years, and the other two men to slightly less. Defense lawyers asked him to instead sentence their clients to the roughly five years they had already served. The three defendants, dressed in orange prison garb, asked to be sent home to their families.

But after a hearing that lasted most of the day and played out before a courtroom packed with dozens of family members, friends and other supporters of the men, the judge rejected those ideas. He instead sentenced Mr. Heard to 12 years and seven months; Mr. Liberty to 14 years; and Mr. Slough to 15 years.