TRIPOLI, Libya (AP) -- A rival Libyan jihadi group has driven an Islamic State affiliate from most of its eastern stronghold of Darna, in fighting that killed 40 militants on both sides, officials said Thursday.

They said that at least 27 IS fighters were killed the night before when the Shura Council of Jihadis attacked the group in the coastal city, where IS gained its first foothold in Libya last year. Medical officials said 13 Council fighters were killed and 20 wounded.

The Council said in a statement that the push Wednesday night had driven the last IS remnants from the city center. It plans to pursue the remaining IS fighters, who have fled to the nearby mountain suburb of al-Fatayah.

Forces loyal to the internationally recognized government based in Libya's east have meanwhile surrounded Darna and were moving in on it from the south, seeking to drive out all of the jihadis, military officials said. All officials spoke on condition of anonymity because they were not authorized to brief reporters.

Libya is bitterly divided between an elected parliament and government based in the eastern city of Tobruk, with little power on the ground, and an Islamist militia-backed government in the capital, Tripoli. Hundreds of militias are aligned with either side or battling on their own for power and turf.

Troops loyal to the eastern government and led by Gen. Khalifa Hifter have surrounded Darna for months and until recently appeared to refrain from getting involved in the fighting between the various jihadi militias.

Last month, the al-Qaida-linked militias pushed most of the Islamic State militants out of the city center, which they had controlled since late last year.

Meanwhile peace talks between some of the warring factions continue. The U.N. envoy for Libya, Bernardino Leon, has urged the Islamist-backed government in Tripoli to sign a peace deal that would establish a unity government. Members of the Tobruk government and regional leaders signed the unity accord in Morocco earlier this month.

The United Nations said in a statement that Leon will hold consultations later on Thursday and Friday in Algiers with representatives of the Tripoli government to discuss ways to move the dialogue forward.