Feeding on the chaos that has gripped Libya since the overthrow and killing of longtime dictator Moamer Kadhafi in 2011, jihadists have used the country to recruit and export militants.
Salman Abedi, the man suspected of carrying out the attack on a pop concert in Manchester that killed 22 people and wounded dozens, was born in Britain but visited Libya before the bombing that was claimed by the Islamic State group.
At the start of the uprising against Kadhafi, dozens of Libyans who lived abroad travelled home to take up arms alongside other Muslim extremists against the veteran strongman.
They were supplied weapons by Western countries and fought the regime as NATO warplanes provided them with air cover.
Post-Kadhadi Libya quickly turned into a breeding ground for heavily armed groups, including Islamists, some of whom were paid by transitional authorities to secure the country's borders.
Among them was the Al-Qaeda-linked Ansar al-Sharia which wooed jihadists and slowly spread its presence from Libya's second city Benghazi to Derna in the east.
Ansar al-Sharia was also present in Sirte, Kadhafi's hometown which was the Islamic State group controlled for more than a year before they were routed by Libyan pro-government forces late last year.
The Islamists who fought Kadhafi controlled army barracks and installations in the east and south of the country after his demise and transformed them into training camps.
Hundreds of jihadists were trained to fight in Iraq and Syria.
The recruits first received ideological guidance and then military training, experts say.
Thanks to Libya's long and porous borders with Egypt and Tunisia, networks were able to radicalise, train and send fighters to battlefields in Syria and Iraq.
Foreign jihadists flooded Libya to prepare for battle.
Some joined Al-Nusra Front, Al-Qaeda's Syria affiliate now known as Fateh al-Sham, while others joined ranks with its rival the Islamic State group.
As IS faced repeated setbacks in Syria and Iraq at the hands of the US-led international coalition, some fighters returned to Libya.
Despite losing Sirte to pro-government forces in December, IS continues to be active in Libya, particularly in the country's remote south and in the east.
According to analysts, IS diehards in Libya consist of fighters from many nationalities.
Mattia Toaldo, senior policy fellow at the European Council on Foreign Relations, said Manchester bombing suspect Abedi could have been trained in an IS camp before the jihadists were routed from Sirte.
The Washington Institute think-tank says that "previously, most of the foreign fighters travelling to Libya hailed from Algeria, Egypt, Morocco, the Palestinian territories, and Tunisia.
"Yet once IS became the main recruiter there, individuals from Europe, North America, South Asia, and other parts of the Middle East and Africa began to show up as well."
Although the Islamic State group claimed the Manchester bombing there has been no confirmation it was behind the attack.
"If the Manchester attack is definitively tied to IS cells in Libya, it would show that the group can still be a lethal actor even without holding territory there," said the Washington Institute.