The Libya connection in the May 22 Manchester concert suicide bombing and Friday's attack on Christians in Egypt has shone a light on the threat posed by militant Islamic groups that have taken advantage of lawlessness in the troubled North African nation to put down roots, recruit fighters and export jihadists to cause death and carnage elsewhere.
Libya has been embroiled in violence since a 2011 uprising toppled and killed Moammar Gadhafi. Vast and oil-rich, Libya currently has rival administrations, an army led by a Gadhafi-era general as well as powerful Islamist militias that compete for territory, resources and political leverage.
At the peak of its power in Libya, the Islamic State group controlled a 160-kilometer (100-mile) stretch of Libyan coastline and boasted between 2,000 and 5,000 fighters, many of them from Egypt and Tunisia.
It is that Libya that the alleged Manchester bomber, 22-year-old British citizen Salman Abedi, found when he and his family moved back from Britain after Gadhafi's ouster in 2011.
Monday's bombing left 22 dead, including an 8-year-old girl, and was claimed by IS. Abedi's brother Hashim has been taken into custody in Tripoli and, according to Libyan authorities, has confessed that he and Salman were IS members.
In Egypt, President Abdel-Fattah el-Sissi sent his fighter-jets to bomb militant positions in eastern Libya just hours after IS fighters shot dead 29 Christians on their way to a remote desert monastery. The military said the attackers were trained in Libya.
Egypt also has long complained that weapons smuggled across the porous desert border with Libya have reached militants operating on its soil. It also has claimed that militants who bombed three Christian churches since December received military training in IS bases in Libya.
Genesis of Libya's militancy:
Hundreds of Libyan youths answered the call to Jihad in the 1980s, traveling to Afghanistan to fight against the Russians. When they returned home after the war, Many of them wanted Islamic Sharia laws implemented in their country. They formed underground cells to escape the regime's watchful eyes and unsuccessfully tried to assassinate Gadhafi.
After Gadhafi's fall, veteran jihadists, al-Qaida sympathizers and Islamists of all shades formed militias that filled the post-Gadhafi power vacuum. Libya's present woes are rooted in the failure of the very first transitional government to dismantle those militias and integrate them into a national army. Instead, they carved up Libya into fiefdoms.
Where are the militants now?
Darna: The eastern Libyan city, where militant positions were targeted by Egyptian warplanes on Friday, has historically been a bastion of radical Islamic groups as well as highly respected Islamic scholars. Extremists made the city their stronghold in the 1980s and 1990s, protected by the rugged terrain of the surrounding Green Mountain range. It was the main source of Libyan jihadists for the insurgency in Iraq. Entire brigades of Darna natives are known to be fighting in Syria's civil war.
During the 2011 uprising, residents formed the "Abusaleem Martyrs" brigade to fight Gadhafi loyalists. It proved to be one of the most effective rebel outfits. Its ranks soon later swelled and its fighters seized the city, setting up the Darna Mujahideen Shura Council to replace the local government.
The Islamic State group's Libyan affiliate had a robust presence in Darna, but the IS faction eventually fell out with the council and was driven out. The IS fighters relocated to the coastal city of Sirte and Darna remains to this day under the control of the Mujahideen Shura Council.
Benghazi: Benghazi, Libya's second largest city, was the first to fall under the influence of extremist Islamic militias. Many of those militias were formed to fight the Gadhafi regime in 2011 and were led by radicals, widely viewed as experienced and motivated.
Perhaps the most notorious of the Benghazi militias is Ansar Al-Sharia, blamed for the killings of hundreds of former Libyan soldiers and for the death of the U.S. ambassador in 2012.
For more than two years, the so-called Libyan National Army led by Gen. Khalifa Hifter has battled an alliance of Benghazi's militias. His forces have managed to secure most of the city, except for pockets of a seaside neighborhood, heavily fortified and surrounded by fields of land mines.
Sirte: Sirte was where Gadhafi and his loyalists made a last stand in the 2011 civil war. The city, Gadhafi's hometown, was almost completely destroyed in the fighting. Furious over the city's loyalty to Gadhafi, anti-government rebels punished the city's residents with extrajudicial killings and revenge attacks.
In 2013, Sirte fell under the control of Ansar Al-Sharia, which made alliances with local tribes and an uneasy truce with other militias and the small number of remaining army troops. The group took over a sprawling former Gadhafi compound and boasted its own TV and radio station. IS also slowly infiltrated the city as fighters from countries like Mali, Tunisia, Egypt and Syria moved in and later declared Sirte an IS emirate.
Last year, militiamen from Misrata and other localities in western Libya, acting with the support of a U.N.-backed government in Tripoli, waged a protracted and bloody campaign to drive IS militants from Sirte. When fighting stalled, the government sought support from the United States, which responded with airstrikes that sped up the collapse of IS in the city.
IS was finally defeated in Sirte and the fighters who survived the carnage fled to the vast deserts to the south.
Sebratha: Sebratha has earned a reputation as a small but tenacious stronghold of Islamic radicals, something that made it easier for IS militants to find a foothold there and spawned a lucrative business in human trafficking to Europe. The city is the main IS gateway due to its location near the Tunisian border. The jumble of various militias have helped IS keep a low profile in the city, but a 2016 U.S. airstrike that killed about 40 of the group's operatives highlighted their presence in Sebratha.