Prosecutors said 14 people received lesser sentences in the case that involved a total of 33 defendants, state media reported on Tuesday.
The accused were found guilty of causing the deaths of 53 people, prosecutors said.
The original case involved the referral of 41 people in relation to activities that had “harmed the sanctity of the country and social security”, prosecutors said.
They said the ISIS members had resorted to “violence and armed operations in Sabratha and its surroundings”.
ISIS and other armed groups proliferated in Libya after the fall of Muammar Qaddafi in a Nato-backed uprising that led to his removal and death in 2011.
The militant group entrenched its forces into the port city of Sirte turning it into the largest ISIS stronghold outside of Syria and Iraq. Human Rights Watch documented the unlawful execution of at least 49 people under ISIS rule, through decapitation and shooting.
ISIS would often accuse those it killed of being "spies" or "sorcerers" as a justification for its actions against them and is known to have kidnapped and forcefully disappeared "dozens" of people, HRW said.
The extremist group was largely defeated in Libya in 2016 by forces loyal to the former UN-backed Prime Minister Fayez Al Sarraj but attacks continued until as recently as 2019 in the country.
Analysts said divisions and rivalries between governments in the east and west had created an environment ripe for such armed groups to fester, enabling ISIS to mount attacks against both sides.
Group trials against suspected ISIS members are also continuing in Libya, with the verdicts often resulting in death sentences.