Tripoli: The Islamic State group said it carried out a double bombing that targeted the empty residence of Iran's ambassador to Libya today.

A security official said no one was hurt in the latest attack on a diplomatic mission in Tripoli, where most embassies have been shut since summer 2014 as rival militias battle for control of the city.

One device exploded outside the security gate and a second was lobbed into the grounds, a security spokesman in Tripoli, Issam al-Naass, told AFP.

Another security source said no one was injured as "the building was empty and the guard was not at his post at the time of the attack".

The jihadist group claimed responsibility for the bombings in a statement on Twitter, saying "soldiers of the caliphate (IS) launched a double attack on the Iranian embassy in Tripoli with explosives".

In Tehran, foreign ministry spokeswoman Marzieh Afkham spoke of "minor damage" to the residence and called for a political dialogue in conflict-hit Libya to counter "terrorists and extremists".

She said Iran opposes foreign intervention in Libya, where talks between the North African country's rival factions must lead to the creation of a national unity government.

Tripoli was seized last August by the Fajr Libya militia alliance after weeks of bloody fighting that triggered an exodus of foreign residents and prompted most diplomatic missions to close.

The Iranian envoy's residence is in an area of the city where several embassies are located.

Witnesses said windows at the nearby Ukrainian embassy were shattered by the impact of today's blasts.

In January, IS claimed responsibility for an attack with explosives on the empty Algerian embassy, wounding a security guard and two passers-by.

IS extremists have been gaining ground in Libya, feeding on chaos that has engulfed the country since dictator Moamer Kadhafi was toppled and killed in a 2011 NATO-backed uprising.

The country is awash with weapons and has two rival governments and two rival parliaments, with authorities unable to rein in powerful militias battling for power and to control the nation's oil wealth.