MOSCOW — Russia has evacuated all its embassy staff and their families from Libya to Tunisia after its mission in Tripoli was attacked, the foreign ministry in Moscow said on Thursday.

The ministry said the decision had been made after Libya’s foreign minister said Libyan authorities were no longer able to guarantee the staff’s safety after Wednesday’s attack. The embassy staff were to fly to Russia today.

Russia’s embassy in Tripoli came under fire on Wednesday and a group of up to 60 people tried to force their way into the compound, the ministry said.

Diplomatic sources in Libya said security guards fired shots to disperse the protesters who had approached the embassy.

An attempt to enter the building was repelled and according to the foreign ministry no diplomats were wounded.

"The attackers opened fire and tore the Russian flag," the Russian Itar Tass news agency cited unnamed sources as saying.

Embassy staff had been taken to the airport as a precaution.

The attack was symptomatic of volatility in Libya two years after the overthrow of Muammar Gaddafi. Tribal rivalries, as well as Islamist groups, have flourished in the absence of strong central government. Security services, themselves riven, have struggled to maintain order.

Western states, using air power, led the military campaign that ultimately toppled Mr Gaddafi.

Russia, which had had close relations with Mr Gaddafi, did not take part in the action and condemned what it called the West’s abuse of a United Nations Security Council motion to intervene.

There have been several attacks on western diplomats by militant groups. Militants linked to al-Qaeda affiliates attacked the US consulate in Benghazi and killed ambassador Christopher Stevens and three other Americans on September 11 last year.

However, one Libyan security source said the attack did not appear to be directly linked to any militant group. He said the crowd were angered by the killing, as they saw it, of a Libyan by a Russian woman. "The group attacked the compound as an act of revenge," said the source.

The embassy was empty at the time. Sources said Libyan authorities were searching for the gunmen.