By Ahmed Elumami
TRIPOLI (Reuters) - Heavily armed gunmen stormed a luxury hotel in Tripoli favored by Libyan officials and visiting delegations on Tuesday, killing at least nine people, including foreigners, before blowing themselves up with a grenade.
Officials said shooting erupted inside the five-star Corinthia Hotel and security forces evacuated guests, including Tripoli's prime minister and an American delegation, after at least two gunmen blasted through the building's reception.
It was one of the worst assaults targeting foreigners since the 2011 civil war that ousted Muammar Gaddafi and fractured the oil-producing North African state into fiefdoms of rival armed groups with two national governments, both claiming legitimacy.
Militants claiming ties with Islamic State in Iraq and Syria said in a Twitter message they were responsible for the attack, which they said was revenge for the death in the United States of a suspected Libyan al Qaeda operative, according to the SITE monitoring service.
But Tripoli officials who have set up their own self-proclaimed government blamed Gaddafi loyalists bent on killing their prime minister, who was at the hotel, and said he was rescued without injury.
"The attackers opened fire inside the hotel," Omar Khadrawi, head of Tripoli security, told Reuters. "When the attackers were completely surrounded by the security forces, one of them detonated a grenade, but we don't know if it was deliberate."
Tripoli security spokesman Essam Naas told Reuters later that an American and a Frenchman were among five foreigners killed. He said the other foreigners who died at the hotel were Asian but gave no nationalities.
Two U.S. officials earlier said they were investigating whether an American was killed in the attack. A security officer was also killed in the clashes and three guards died when the attackers set off a car bomb in the car park outside the hotel.
Most foreign governments closed their embassies and pulled staff out of Tripoli after factional fighting erupted in the capital last summer. But some diplomats, business and trade delegations still visit the capital.
Envoys from the United Nations, which is holding talks in Geneva with some of Libya's warring parties to try to end hostilities, have also been in Tripoli.
Libya is caught in a conflict between the two rival factions, one allied with the internationally recognized government, the other with "Libya Dawn" forces who took over Tripoli in the summer and set up their own government.
But in Libya's post-revolution chaos, armed groups, from brigades of former rebels to federalist fighters and Islamist militants, have grown in power and control more territory.
Islamist militants, including those who claim loyalty to Islamic State, operate in pockets of Libya, especially eastern Benghazi and Derna. Recently, they claimed to have kidnapped two Tunisian journalists, and groups of Egyptians.
Foreigners and embassies have also been targeted in shootings, kidnappings and bombings in the past.
In 2012, militants attacked the U.S. Consulate in Benghazi, killing the U.S. ambassador and three other Americans. U.S. officials blamed a Libyan Islamist group, Ansar al Sharia, for orchestrating that attack.
The Corinthia, a luxury high-rise overlooking the capital's coastline, is frequently used by top government and foreign delegations. In 2013, the then-Libyan prime minister was briefly abducted from the hotel by former rebels on the state payroll.
On Tuesday, Khadrawi, the capital's security director, said security forces had spirited the Tripoli government's premier, Omar al-Hassi, from the 22nd floor of the hotel, where he was staying, to safety. Four Americans were also rescued, he said.
"The attackers were attempting to assassinate him," he said.
But SITE monitors, citing social media, said a militant group had claimed the attack as revenge for the death of Abu Anas al-Liby, a suspected al Qaeda member accused of helping plan the 1998 bombings of the U.S. embassies in Tanzania and Kenya. Liby died in a New York hospital this month ahead of his trial.
The Libyan national was snatched by U.S. Special Forces from Tripoli in 2013.
Since the 2011 NATO-backed uprising that toppled Gaddafi, Libya has struggled to find stability and a conflict has gradually emerged between two loose confederations of politicians, armed groups and regional factions.
Tripoli is controlled by a faction that is allied to the city of Misrata and their powerful armed forces, but also includes some Islamist-leaning former rebel fighters and politicians allied to the Muslim Brotherhood.
They are faced by the internationally recognized government of Prime Minister Abdullah al-Thinni and the elected parliament who now operate out of the east of Libya. Thinni's government is allied to several armed factions, including a former Gaddafi army general battling Islamist militants in Benghazi.
(Writing by Patrick Markey and Ulf Laessing; Editing by Mark Heinrich and Jonathan Oatis)