A ceasefire has been signed between armed factions fighting over the Libyan capital, the United Nations said on Tuesday, after more than a week of violence inside Tripoli.