Libya, once the gateway for African immigrants seeking to cross the Mediterranean to Europe, is increasingly putting up its shutters.
The latest sign of this is the government's decision to close the offices of the UN High Commission for Refugees in Tripoli, saying it was illegal, and thus denying migrants and asylum seekers a lifeline if they run into trouble in their efforts to make the treacherous coastal journey to Europe.
Although the closure sparked protests from rights groups, the European Union's response was more muted, saying it was regrettable but understandable.
"There's a certain fear in the country that with the presence of the UNHCR, more refugees are being attracted to Libya," Adrianus Koetsenruijter, the EU ambassador accredited to Libya, told the BBC on a recent visit to Tripoli.
"And [this is] thereby causing a bigger problem inside the country," he said, adding he hoped the refugee agency would be able to operate there again.
Just days after the closure, the EU signed a $60m (£40.5m) financial and technical co-operation pact with Libya, as a prelude to a wider deal expected to be sealed by the end of the year.
This shows the current thinking in European capitals: that Col Muammar Gaddafi's Libya - once a pariah state accused of promoting terrorism to threaten Western interests - is now a key ally in efforts to tackle illegal immigration from Africa.
It is also a vital source of oil and gas resources with a plethora of investment opportunities in this "virgin" market.
And Libya, with trade links and Western know-how as an incentive to open up its economy to foreign investors after decades of isolation, has taken far-reaching measures to help European governments achieve their objective.
It is now fighting illegal immigration on land and at sea.
This has led to a crackdown on human-trafficking syndicates, the detention and deportation of illegal migrants, and joint sea patrols with the former colonial power, Italy - something that was once unthinkable as Libya promoted a pan-African vision free of Western influence.
Expressing his satisfaction with Libya's actions, Mr Koetsenruijter said illegal immigrant landings on Italian and Maltese shores are "almost zero now".
The recent financial deal signed with the EU will partly continue to finance tighter border controls.
The head of the International Organization for Migration in Libya, Lawrence Hart, believes that Libya is becoming a dead end for migrants hoping to reach Europe.
"As it stands, it is a dead end - not down to zero but down by 95% of landings in Italy and Malta," he says.
"This is also thanks to the country actually exercising the restrictions."
But he believes that the best way to curb illegal immigration is by tackling head-on the dire economic situation in many African countries.
"It's always a precarious situation because it can burst any time.
"Until the root causes are addressed, migration flows are likely to continue for many reasons, not least because there are work opportunities in Libya that remain attractive."
Tripoli's sporadic policy of rounding up foreigners who fail to produce a work permit also means many illegal immigrants are nervous about staying long-term.
The execution of several African nationals accused of premeditated murder - though not a new development - made headlines this month.
It sparked condemnation from human rights organisations who voiced concern that the trials did not meet international standards, while the Ghanaian government appealed to Tripoli to give clemency to its citizens facing the death penalty.
The mood among European diplomats, however, is different: A far cry from the days when they sniped at Libya for failing to curb immigration, or denounced it for its failure to adopt Western-styled democracy and human rights values.
It shows how the political tide is changing in Libya, as it seeks to strengthen relations with European countries that it once accused of undermining African sovereignty and trying to re-colonise the continent.