BENGHAZI, Libya (AP) — The Islamic State group this week lost the city of Sirte, its only foothold in Libya, essentially ending its ambition to expand its self-styled "caliphate" into the North African nation, at least for now.
But that victory only opens the door for Libya's multiple armed factions to turn on each other in a new showdown. It could be over control of oil, the North African nation's only real source of revenue.
A U.N.-brokered peace deal was reached a year ago, trying to establish a unity government to end the chaos that has plagued Libya since the ouster and death of longtime strongman Moammar Gadhafi in a 2011 civil war. Instead, the country remains divided roughly between east and west, there is still no effective government and rival factions and militias — each side with backing from foreign countries — threaten a new chapter of violence.
Here are some issues at stake:
THE ISLAMIC STATE GROUP'S FATE
The loss of Sirte, on Libya's long Mediterranean coast, is a significant reversal of how things looked in the summer of 2015 when IS took the city. With Libya in chaos, it appeared there was nothing to stop the group from expanding and building a stronghold just across the Mediterranean Sea from Europe.
The militants imposed a brutal rule in Sirte much like in Iraq and Syria, committing out atrocities, taking sex slaves and carrying out beheadings of Christians and migrants. Militants affiliated to al-Qaida and other groups rebranded themselves with the IS affiliate to gain power and resources.
The neighboring city of Misrata, home to some of Libya's strongest militias, led the fight to drive out IS, feeling threatened by the extremists next door. Misrata militias launched an offensive and in August the United States joined in with airstrikes. In months of tough fighting, more than 700 Misrata fighters were killed and 3,200 were wounded. This week, the last IS positions were taken.
However, many of the estimated 2,500 militants likely escaped. The Misrata-led forces have not said how many were killed.
It is feared that potentially hundreds of IS fighters will find refuge in Libya's lawless south and regroup, able to carry out attacks and re-emerge as player at any time. Al-Qaida-linked extremists already have bases in Libya's vast desert regions, building ties with local tribes.
EAST VS WEST
With IS out of the way for the moment, Libya's rival domestic powers are face to face with each other.
The powerhouse in the east is Field Marshal Khalifa Hifter, who commands the Libyan National Army, composed of Gadhafi-era officers, remains of the national military and civilians-turned-fighters. The force is backed and armed by neighboring Egypt, which sees Hifter as its ally in a fight against Islamic militants.
Hifter's army backs Libya's last elected parliament, which was driven out of Tripoli in 2015 when Islamist-leaning militias and the Misrata militias took over the capital in a blitz. The parliament is now based in the eastern city of Tobruk, and the interim government based on it is in the nearby city of Beida.
After two years of fighting, Hifter's forces are nearing victory over Islamic militants in Benghazi, Libya's second largest city. The militants, under an umbrella group called the Benghazi Shura Council, were allied with Islamic State group fighters in the eastern city, along with fighters from Ansar al-Shariah, the al-Qaida-affiliated group blamed in the deadly 2012 attack on a U.S. diplomatic mission in Benghazi.
In the west, Hifter's strongest rivals are the militias of Misrata, where the general is seen as aspiring to become another Gadhafi. The Misrata militias are believed to receive arms from Turkey.
Who rules in the west? It's complicated.
The U.N.-brokered peace deal created a Presidency Council, a unity government and an advisory body called the Advisory Council. The Presidency Council's head, Fayed Serraj, arrived in Tripoli in March and are now the internationally recognized authority in Libya. The Misrata militias nominally back the council.
But the council has little power. The Tobruk parliament refused to endorse the peace deal because it would give the Presidency Council control over the army, effectively squeezing out Hifter.
So local militias hold sway across the west. And there is another rival claimant in Tripoli, the so-called National Salvation Government, headed by Khalifa Ghweil. It is rooted in a former Islamist-dominated parliament, whose allied militias took over the capital in 2014.
This is the prize Hifter and the Misrata militias may battle for.
Hifter currently holds it. A few months ago, his forces took over oil terminals in the east, driving out a militia led by a commander named Ibrahim Jedran. Jedran's fighters and some anti-Hifter Benghazi militias have been trying unsuccessfully to take the facility back.
The capture gave Hifter considerable leverage. Libya's Gadhafi-era production reached 1.6 million barrels a day, but in the post- 2011 chaos it collapsed, costing it more than $100 billion in lost profits the past three years. The industry is rebuilding, now producing 600,000 barrels a day and aiming to rapidly increase.
The United States and U.N. have called on Hifter to hand over the facilities to the Presidency Council.
But Hifter is more likely to use them as leverage to force a rewriting of the peace deal.
The fear is that the fighting between Jedran and Hifter will escalate, prompting the Misrata militias to join the fight. Or Misrata could lose patience and attack its rival Hifter on its own.
THE PEACE DEAL
Under the peace deal, Libya was supposed to have had a unity government in place the past year with all the militias grouped under a single national command. By now, the country was supposed to be virtually finished with writing a new constitution.
Instead, Serraj and his authorites are maneuvering to try to gather at least some powers. They had to strike deals with Tripoli militias just to leave the naval base where they first arrived and move into offices. The Central Bank, following the Tobruk parliament's lead, largely refuses to give him funds. As a result, the council has few tools to deal with electricity and water shortages.
The Tobruk parliament demands the peace deal be reworked to alter the makeup of the Presidential Council and keep the military under its — and therefore Hifter's — authority. The Misrata militias and others in the west reject the idea of Hifter dominating the armed forces.
Unless one side backs down, the country risks an explosive fight.
The International Crisis Group said in a recent report that the deal is unworkable and advised, "Time to reset."
On Tuesday before the U.N. Security Council, Martin Kobler, the U.N. envoy to Libya, said there is no alternative to the peace deal. "It's the only workable framework."
But, he added, "its articles are not set in stone."