Algeria has closed its embassy and its consulate in Tripoli because of a "real and imminent threat" to its diplomats, the foreign ministry announced on Friday.