The bomb blast that wrecked much of the embassy is seen as a reprisal by Libyan militants for the decision by Paris the day before to extend its military mission against fellow jihadists in Mali.
The Guardian has learned that jihadist groups ejected from their Timbuktu stronghold have moved north, crossing the Sahara through Algeria and Niger to Libya, fuelling a growing Islamist insurgency.
"There are established links between groups in both Mali and Libya – we know there are established routes," said a western diplomat in Tripoli. "There is an anxiety among the political class here that Mali is blowing back on them."
That anxiety escalated last week after militants detonated a car bomb outside the French embassy, wounding two French guards and a Libyan student, the first such attack on a western target in the Libyan capital since the end of the 2011 Arab spring revolution.
"The armed groups we are fighting are fleeing to Libya," said Colonel Keba Sangare, commander of Mali's army garrison in Timbuktu. "We have captured Libyans in this region, as well as Algerians, Nigerians, French and other European dual-nationals."
France sent troops to Mali in January after an uprising in the north started by the ethnic Tuareg National Movement for the Liberation of Azawad (NMLA), named for the independent state it hopes to create.
The impetus for this uprising came from ethnic Tuareg soldiers who had fought alongside Muammar Gaddafi and fled south when his regime fell. They were later augmented by jihadists from Libya and across northAfrica, who triggered international condemnation for their destruction of ancient Sufi Muslim shrines in Timbuktu. The fear across the Maghreb is that the French operation that has pushed them out of the northern cities has inadvertently compounded problems elsewhere in north Africa as jihadist units disperse.
"If you squeeze a balloon in one part, it bulges out in another," said Bill Lawrence, of International Crisis Group, a political consultancy. "There's no question that the French actions in Mali had the effect of squeezing that balloon towards Algeria and Libya."
Timbuktu residents say there are links between Tuareg militants there and in southern Libya. "There were many Tuaregs in Mali who left during the drought of 1973 – some of them became senior figures in the Libyan army under Gaddafi," said Mahaman Touré, 53. "I personally know a local Tuareg who became a general under Gaddafi and was here with the jihadists. Now they have all gone back to Libya."
Diplomats say jihadists cross the Sahara to join cadres in Libya's eastern coastal cities of Benghazi and Derna. Police stations in both cities have been hit by bombings in the past few days, part of an insurgency that threatens to undermine the country's fragile new democracy. Chad's president, Idriss Déby, claimed at the weekend that Benghazi was now home to training camps for Chadian rebel fighters.
"From the perspective of an Islamist, it makes sense," said Dr Berny Sèbe, an expert on the Sahara region from Birmingham University. "If you are in northern Mali, the best thing that you can do is to make your way across Niger and then into southern Libya, where there is no state control."
Eastern Libya has long been a base for Islamists, who launched an unsuccessful uprising against Gaddafi in the 1990s. Their units reappeared in the uprising two years ago, and while many have integrated with government forces, others are campaigning for a state ruled by clerics rather than secular politicians. Benghazi has become a virtual no-go area for foreigners following attacks on the British, Italian and Tunisian consulates, the fire-bombing of an Egyptian Coptic church and the killing of US ambassador Chris Stevens in September when militants overran the American consulate. The bombing in Tripoli indicates that terrorism has now spread to the capital.
"Libya suffers this Mali blowback in two ways," said a diplomat in Tripoli. "First there are the fighters arriving here, second there are units carrying out attacks in support of their brothers [in Mali]."
The result is not only being felt in Libya. In January, units from al-Qaida in the Maghreb, an Algerian-based al-Qaida offshoot, struck the In Amenas gas plant, killing 38 hostages, in what they said was retaliation for the France's Mali offensive.
Ordinary Libyans are suffering. Watching French police investigators sifting through the mangled wreckage outside the abandoned embassy, neighbour Emad Tillisy, a Tripoli businessman, shook his head. "This is so bad for Libya," he said. "It is the worst message we can send out to the world. We need to have foreigners coming here for business, to build our country, but after this [bombing] they say 'no thanks, have a nice day'."
Libya's efforts to tackle the militants are restricted by the distrust felt by much of the population for government security units, many of them drawn from former Gaddafi-era formations. Twin rocket attacks on oil and gas pipelines earlier this month south of Benghazi have meanwhile sent a shudder through Libya's oil industry, almost its only export earner.
Libya has already piled resources into cutting the jihadist flow of men and weapons over its southern border, declaring its entire desert region a "free fire zone" for patrolling jets. In the south-west, work has now finished on a 108-mile trench cut through the desert to deter smugglers crossing into Libya.
But experts say the Libyans face a herculean task. "To ensure that these borders are completely sealed off is impossible – we are talking about desert areas with mountains and very narrow valleys," said Sèbe.
Libya's prime minister, Ali Zaidan, has vowed to launch a clear-out of militias in Benghazi, but many wonder if he has enough reliable units for the job.
In December Washington provided drones and an Orion electronic warfare aircraft to support government units arresting jihadist suspects in Benghazi. It is now delivering border surveillance equipment to Libya and setting up a base for drones in Niger, from where it can monitor both Mali and Libya.
This policy has its critics, who say experience in Afghanistan and Iraq shows military action works only when coupled with a political process that ensures the grievances of all sections of the population are met, denying militants popular support. "A drone-only approach to intelligence gathering can backfire," said Lawrence. "There's always bad guys who may blow up buildings – the question is what sea are they swimming in? The priority should be the support of a legitimate government that reflects the aspirations of all elements of Libyan society."
The rise of Islamism in north Africa has spawned a galaxy of competing jihadist organisations, with alliances as fluid as the borders they cross. The units that staged the northern Mali uprising were drawn from both Libyan Tuareg fighters and jihadists, despite the fact that they fought on opposite sides in Libya's civil war. "For me, they are all the same – the Islamists and the MNLA," said Ahamadou Tahir, who was attacked by militants while delivering medical supplies 60 miles north of Timbuktu. "They all have guns and they all want to cause us harm."