The ISIS group tried Sunday to break a siege on their last holdouts in Sirte but were pushed back by fighters allied to Libya's unity government, a spokesman said.
ISIS fighters have been pinned down in parts of Sirte since forces allied to the UN-backed Government of National Accord (GNA) launched an operation to dislodge them from the coastal city last month.
On Sunday pro-GNA forces said they clashed with the militants who had launched a bid to break away from positions west of Sirte using "medium-sized" weapons.
"Our forces confronted them and forced them to retreat," spokesman Reda Issa told AFP.
"Two of our men were killed and five wounded" in the clashes around the Al-Ghrebat sector of Sirte, he said.
Militant groups took root in Libya in late 2014, taking advantage of the chaos and power struggles that followed the NATO-backed uprising that toppled and killed dictator Moamer Kadhafi in 2011.
The pro-GNA forces launched an operation to drive ISIS out of Sirte on May 12.
Last week they imposed a siege around the Mediterranean city and advanced into parts of it but the operation has slowed down with jihadists holed up in residential areas.
"The pro-government forces are advancing cautiously because ISIS fighters are barricaded inside homes and we are trying to avoid using heavy artillery to spare civilians who could also be inside," said Issa.
ISIS has counter-attacked during the past week, including with suicide bombings that have killed at least nine pro-GNA forces.
Issa said the pro-GNA forces were now focused on trying to "bolster their positions on the outskirts of Sirte to reinforce the siege and provoke ISIS fighters to come out of hiding".
At least 166 pro-GNA forces have been killed and more than 500 have been wounded since the assault was launched last month, according to an AFP count based on reports from medical officials.
No casualty figures are available for the jihadists in Sirte, 450 kilometres (280 miles) east of the capital.
US officials estimate ISIS has 5,000 fighters in Libya, most of them in Sirte, where the remaining civilian population numbers around 30,000.SHOW MORE