“We heard a loud explosion,” said a Tripoli resident living next to the embassy.
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.
Militants loyal to Islamic State have claimed a string of killings of foreigners as well as attacks on embassies and oilfields in Libya.
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. (Reuters)