A Tunisian court has sentenced seven jihadists to life in prison over attacks at a museum and on a beach in 2015 that killed a total of 60 people, prosecutors have said.

Dozens of defendants faced two separate trials over the closely linked shootings, which occurred just months apart in Tunis and Sousse, but many were acquitted.

Three were given life sentences for homicide for the first attack in March 2015 at the capital’s Bardo Museum, in which two gunmen killed 21 foreign tourists and a Tunisian security guard.

Four received the same term for the shooting rampage at a Sousse tourist resort in June that year, which killed 38 people, mostly British tourists. Other defendants were sentenced to between six and 16 years, the prosecution spokesman Sofiene Sliti said on Saturday.

Prosecutors said they planned to launch appeals in both cases.

The court heard that the two attacks, for which Islamic State claimed responsibility, were closely linked.

Several defendants said the fugitive Chamseddine Sandi was the mastermind of both.

According to Tunisian media, Sandi was killed in a US airstrike in neighbouring Libya in February 2016, although there has been no confirmation.

Among those facing trial were six security personnel accused of failing to provide assistance to people in danger during the Sousse attack.

That shooting was carried out by Seifeddine Rezgui, who opened fire on a beach before entering a hotel, where he continued to fire a Kalashnikov and throw grenades until he was shot dead by police.

Four French nationals, four Italians, three Japanese people and two Spaniards were among those killed in the Bardo attack, before the gunmen were shot dead.

Investigations showed one of the gunmen, Yassine Laabidi – who was born in 1990 and was from a poor district near Tunis – had amphetamines in his body. The other, Jaber Khachnaoui – born in 1994 and from Tunisia’s deprived Kasserine region – had travelled to Syria in December 2014 via Libya.

One suspect questioned in court, Mahmoud Kechouri, from Tunis, said he had helped plan the Bardo attack, including preparing mobile phones for Sandi, who was a neighbour and longtime friend.

Kechouri, 33, said he was driven by a “duty to participate in the emergence of the [Isis] caliphate”.

Other defendants accused of helping prepare the attack said they had only discussed ideas with friends. Several alleged they were tortured in detention.

Victims’ family members in France and Belgium watched the Sousse attack hearing via a video feed.

“It was important for us to see – and especially to hear – to try to understand the role” of each defendant, said one French survivor. “Arriving at the end of the process will help us to turn the page, even if we can never forget.”

Gérard Chemla, a lawyer for the French victims, said: “The trial allowed them – by organising the video conferencing and giving the floor to lawyers chosen by the victims – to finally be recognised as victims by the Tunisian state.”

He said he lamented the fact that the families of those killed had not been compensated.

The Sousse attack, which killed 30 Britons, is also the subject of proceedings in front of the Royal Courts of Justice in London, which is seeking to establish what happened.

Since a 2011 uprising that toppled the dictator Zine El Abidine Ben Ali, jihadist attacks in Tunisia have killed dozens of members of the security forces. As well as leaving many dead, the Bardo and Sousse attacks seriously affected Tunisia’s vital tourism sector, although it has begun to recover.