Spain’s El Mundo newspaper said nobody had been hurt as Spain, like most Western and Arab countries, had pulled out its diplomats in summer during weeks of heavy fighting between rival armed groups in Tripoli.
Pictures posted on social media showed some damage at the building’s wall. There was no immediate claim for the attack or comments from Tripoli officials.
Islamic State militants have exploited chaos in the North African country where two governments allied to a host of armed groups are fighting for control four years after the ousting of Muammar Gaddafi.
On Sunday, the group claimed the killing of around 30 Ethiopan Christians, two months after the beheading of 21 Egyptian Copts on a Libyan beach.
Libya’s internationally recognized government has been based in the east since a rival faction called Libya Dawn seized Tripoli in August, setting up a rival administration.
(Reporting by Ahmed Elumami; additional reporting by Julian Toyer in Madrid; Writing by Ulf Laessing; Editing by Lisa Shumaker and Leslie Adler)