"Islamic State extremists concealed an explosive device near an exterior wall of the Spanish embassy building in Tripoli, which caused some material damage to it and to neighbouring buildings," local official Issam Naas told AFP.
Several accounts linked to the Libyan branch of IS claimed the attack on Twitter.
The Islamic State, which has seized chunks of Syria and Iraq, has won the support of jihadist groups across Middle East and north Africa. Several militant groups in conflict-wracked Libya have pledged allegiance to the militants.
Libya has been awash with weapons since an uprising in 2011, has rival governments and parliaments and is on the edge of all-out war as armed groups battle to control its cities and oil wealth.