Three men have been sentenced to death in Morocco for the Isis-inspired murder of two Scandinavian hikers in the Atlas mountains last December.

The two victims, Louisa Vesterager Jespersen, 24, from Denmark, and Maren Ueland, 28, from Norway, were beheaded by a group of men who wanted to impress Islamic State. The three men confessed to their murder at a court in Salé, near Rabat.

Morocco has not carried out an execution since 1993, but prosecutors called for the death penalty during the 11-week trial.

Last week a letter from Jespersen’s mother was read out in court which said: “The most just thing would be to give these beasts the death penalty they deserve.”

Prosecutors said Abdessamad Ejjoud, 25, a street vendor and underground imam, was the ringleader and admitted to killing one of the women, and Younes Ouaziyad, 27, a carpenter, confessed to the other murder. The third man, Rachid Afatti, 33, videoed the murders on his phone.

The women’s bodies were found by two French walkers near the tourist hub of Imlil, where the two friends had been spending a holiday. The defendants had stabbed them to death in their sleeping bags and then beheaded them, filming it all and posting it online later. The video went viral, including in Islamic State supporters’ circles and in far right and white nationalist networks, according to an investigation by the Washington Post.

Before the murders the men had made their own Isis flag, which they hung behind them for an allegiance video, but Isis did not accept their pledge or distribute the video.

Louisa Vesterager Jespersen, left, and Maren Ueland were found at an isolated site in the Atlas mountains. Photograph: Social media

The prosecution said all three were “bloodthirsty monsters”, pointing out that an autopsy report had found 23 injuries on Jespersen’s decapitated body and seven on Ueland’s.

The defendants came from poor backgrounds and were badly educated, and the defence team argued there were “mitigating circumstances on account of their precarious social conditions and psychological disequilibrium”.

However, the court ordered the three to pay 2m dirhams (£160,000) in compensation to Ueland’s parents.

“I regret what happened and I am still trying to grasp it,” Ejjoud said in court in May.

Twenty-one other men who were accused of playing a part in the murders or of being linked to Ejjoud are still awaiting a verdict. Some of them denied involvement in the murders in court. The prosecution has called for jail terms of between 15 years and life for them.

Jespersen’s lawyers accused authorities of failing to monitor the activities of some of the suspects before the murders, but the court rejected the family’s request for 10m dirhams in compensation from the Moroccan state for its “moral responsibility”.

The case has shocked Morocco, which welcomes millions of visitors each year, experiences very few terrorist attacks and relies on tourists for 10% of its national income.

The two friends studied outdoor leadership, culture and ecophilosophy together in Norway. Jespersen, who loved the outdoors, dreamed of going to the Arctic but said in a video she posted on social media: “Sometimes I take some detours before I end up where I want.”

Ueland had been uncertain about whether to go on the trip but finally decided to join her friend.