The officials said a suicide bomber was able to detonate an explosive vest inside the building in the centre of Misrata, a coastal city about 200 kilometres (125 miles) east of Tripoli.
"Three men belonging to the Islamic State jihadist organisation carried out a suicide attack against the court complex in Misrata... killing four people and wounding 15 others," General Mohammed Ghassri, a spokesman for armed forces in Misrata that are loyal to the country's internationally backed government, told AFP.
Misrata is home to powerful armed forces who were the backbone of an offensive that routed IS from the coastal city of Sirte in December 2016.
That offensive was backed by Libya's UN-endorsed Government of National Accord (GNA), one of two main rival governments that emerged from the chaos that followed the 2011 ouster of long-time strongman Moamer Kadhafi.
Also Read
There was no immediate claim of responsibility from IS for today's attack, but the jihadist group remains a force in Libya despite losing control of Sirte.
The US military last month carried out a wave of air strikes on IS in Libya, killing 17 people on September 22 at a desert camp 240 kilometres (150 miles) southeast of Sirte.
The US Africa command said the camp was used to move jihadists in and out of the country, store weapons and plot attacks.
In August, IS claimed responsibility for an attack in which 11 people were beheaded at a checkpoint manned by forces loyal to military strongman Khalifa Haftar.
Nine soldiers and two civilians were killed in that attack in the Al-Jufra region about 500 kilometres (300 miles) south of Tripoli.
Disclaimer: No Business Standard Journalist was involved in creation of this content