A Tunisian court has sentenced seven militants to life in prison over attacks at a museum and on a beach in 2015 that killed 60 people, many of them British tourists, prosecutors said on Saturday.
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.
Four were sentenced to life in prison for the shooting rampage at a Sousse tourist resort in June 2015, which killed 38 people, mostly British tourists.
Five other defendants in the Sousse case were handed jail terms ranging from six months to six years, while 17 were acquitted, prosecution spokesman Sofiene Sliti said.
Three were given life sentences for the earlier attack in March 2015 at the capital's Bardo National Museum, in which two gunmen killed 21 foreign tourists and a Tunisian security guard.
Others found guilty of links to the Bardo attack were sentenced to prison terms ranging from one to 16 years, and a dozen defendants were acquitted, Mr Sliti said.
The prosecution will launch an appeal, he added.
The court heard that the two attacks, both claimed by the Islamic State group (IS), were closely linked.
Several defendants pointed to the fugitive Chamseddine Sandi as mastermind of both.
According to Tunisian media, Sandi was killed in a US air strike in neighbouring Libya in February 2016, although there has been no confirmation.
Among those who were 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 rampaging into a high-end hotel, where he continued to fire a kalashnikov and throw grenades until being shot dead by police.
Four French nationals, four Italians, three Japanese and two Spaniards were among those killed in the Bardo attack, before the two gunmen, armed with Kalashnikov assault rifles, were themselves 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.
His fellow attacker 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, Tunis labourer Mahmoud Kechouri, said he had helped plan the Bardo attack, including preparing mobile phones for Sandi, a neighbour and longtime friend.
Kechouri, 33, said he was driven by a "duty to participate in the emergence of the caliphate," that IS supremo Abu Bakr al-Baghdadi proclaimed in June 2014 across swathes of territory the militants controlled in Iraq and neighbouring Syria.
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 Friday's hearing via a live 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."
Gerard Chemla, a lawyer for French victims, said the live feed had brought some degree of comfort to relatives.
"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.
But he lamented 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.
After holding inquests into the British deaths in January and February 2017, judge Nicholas Loraine-Smith concluded that the response of Tunisian police was "at best shambolic, at worst cowardly".
He said hotel guards were not armed and had no walkie-talkies.
There have been substantial improvements in security at Tunisian tourist resorts since the massacre and in July 2017 Britain lifted its warning against "all but essential travel" to the North African country.
The attacks and resulting travel warnings dealt a devastating blow to Tunisia's vital tourism sector from which it has taken time to recover.
Since a 2011 uprising that toppled dictator Zine El Abidine Ben Ali, militant attacks in Tunisia have killed dozens of members of the security forces.
Thousands have also travelled abroad to join militant organisations in Iraq and Syria, Libya, Mali and Yemen, according to the United Nations.