KABUL—An Afghan judge sentenced four men to death by hanging for their role in the murder of a young woman in Kabul by a frenzied mob, a case that has become a test of the country’s resolve to crack down on violence against women.

In March, a group of men beat to death the young woman, Farkhunda, after she was falsely accused of desecrating the Quran, an act considered a grave form of sacrilege in this conservative Muslim country.

Video footage of the beating that was widely shared on Afghan social media showed Ms. Farkhunda being beaten while police looked on without intervening. Her body was thrown in a dry riverbed and then set on fire as a crowd of hundreds watched, with some chanting “Allahu akbar!” or “God is great.”

Cellphone video collected as evidence during the trial showed gang of men gathering around a veiled Ms. Farkhunda in the moments before the attack.

“The Americans sent you,” one man says.