It was not immediately clear who staged the attack, but the SITE monitoring service said a militant group claiming affiliation with Islamic State had claimed responsibility. Islamic State has seized swathes of Syrian and Iraqi territory.
Gunfire could be heard inside the Corinthia Hotel, Tripoli's most prominent hotel where government officials and foreign delegations often stay. There were conflicting reports about the exact number and the identity of those killed as the gunmen battled security forces.
"Eight people were killed during the storming of the hotel... Five foreigners, two of them are women. (Also) one security man and two of the attackers," Mahmoud Hamza of the Tripoli security force told local al-Naba television.
Earlier officials said three security guards had been killed in a car bomb blast just before the gunmen stormed the hotel. It was not immediately clear whether the three were among the eight deaths reported by Hamza or were additional casualties.
Hamza did not give the nationality of the foreigners killed. Other officials gave conflicting accounts of whether any foreign nationals had been killed in the attack.
Most foreign governments closed their embassies and pulled their staff out of Tripoli after fighting between two rival factions erupted last summer. But some diplomats, business and trade delegations still visit the capital.
Libya is mired in conflict between two rival governments -- an internationally recognised one based in eastern Libya and a rival administration set up in Tripoli after an armed faction called Libya Dawn took over the capital.