The Islamic State group has lost vast swathes of territory in Iraq and Syria

Up to 6,000 Africans who fought for the Islamic State (IS) jihadist group in Iraq and Syria could return home, the African Union's top security official warned Sunday, calling on countries to prepare for the threat.

Smail Chergui, the AU's commissioner for peace and security, said African nations would need to work closely with each other and share intelligence to counter returning militants.

"There are reports of 6,000 African fighters among the 30,000 foreign elements who joined this terrorist group in the Middle East," Chergui told a meeting in Algiers, according to the Algeria Press Service news agency.

"The return of these elements to Africa poses a serious threat to our national security and stability and requires specific treatment and intense cooperation between African countries," he said.

Tens of thousands of foreign fighters joined the Sunni extremist group after it seized vast swathes of Iraq and Syria and declared a caliphate in 2014.

But the group has suffered a host of losses to both its territory and military capabilities in the last year.

Backed by a US-led coalition, Iraqi forces gradually retook control of all territory lost to the jihadists, declaring on Saturday that the country was now liberated from its control.

In Syria, the group faces western-backed Syrian rebels, jihadist rivals and government forces that are supported by Russia and Iran.

But the losses have sparked fears that IS's remaining foreign fighters may now relocate, bringing their extremist ideology and violence with them.