File photo showing an Iraqi soldier inspecting a train tunnel, adorned with an ISIS flag. AP
The assailants used automatic weapons in the attack on their barracks in Wadi al-Naft, about 25 kilometres (15 miles) west of the city of Kirkuk, the official said on condition of anonymity.
"Three soldiers, including two officers, were killed, and four other soldiers were wounded," the official told AFP. There was no immediate claim of responsibility.
The attack occurred in an area disputed between Iraq's federal government, which holds Kirkuk, and the country's autonomous northern region of Kurdistan.
IS jihadists seized swathes of Iraq and neighbouring Syria in 2014, declaring a "caliphate" which they ruled with brutality before their defeat in late 2017 by Iraqi forces backed by a US-led military coalition.
Despite the setbacks, the extremist group can still call on an underground network of fighters to carry out attacks on both sides of the porous border, the United Nations says.
In April, the international coalition set up to fight the Sunni Muslim extremists said there had been a reduction in IS attacks in both Iraq and Syria.
In March, a senior Iraqi military official said IS had between 400 and 500 active fighters in the Shiite-majority country.
Short link: