BAGHDAD - Five weeks after a military operation began, a senior Iraqi commander declared Sunday that the city of Fallujah was “fully liberated” from the Islamic State group, giving a major boost to the country's security and political leadership in its fight against the extremists.

Recapturing Fallujah, the first city to fall to the Islamic State group more than two years ago, means that authorities can now set their sights on militant-held Mosul, Iraq's second-largest city.

Prime Minister Haider al-Abadi, visiting central Fallujah with the celebrating troops, vowed that the Iraqi flag would next be raised above Mosul. But that campaign has been progressing in fits and starts, revealing the deep divisions among the different groups that make up the security forces.

Iraqi troops entered Fallujah's northwestern neighbourhood of al-Julan, the last part of the city under IS control, said Lt. Gen. Abdul-Wahab al-Saadi, head of the counterterrorism forces in the operation.

The operation, which began May 22, “is done, and the city is fully liberated,” al-Saadi told The Associated Press.

Al-Abadi, dressed in the black fatigues of the counterterrorism forces and carrying an Iraqi flag, visited Fallujah's central hospital Sunday evening and called for residents of the city 40 miles (65 kilometres) west of Baghdad to celebrate the military advance.

But tens of thousands of people from Fallujah who were forced to flee their homes during the operation are still at overcrowded camps for the displaced with limited shelter in the Anbar desert. The U.S.-led coalition said it was still conducting airstrikes in the area, and aid groups warned it was too early to say when residents could return to their homes in the city, citing the presence of makeshift bombs left behind by the militants.

The Fallujah operation was carried out by Iraq's elite counterterrorism troops, Iraqi federal police, Anbar provincial police and an umbrella group of government- sanctioned militia fighters - mostly Shiites - who are known as the Popular Mobilization Forces.

Fallujah, a predominantly Sunni city, was a stronghold of insurgents following the U.S.-led invasion in 2003. More than 100 American soldiers died and hundreds more were wounded in intense, house-by-house fighting there in 2004. Many residents of the city welcomed the Islamic State group when it overran the city in 2014, complicating the fight by government troops to retake it.

The IS militants who had held out for more than a week on the northern and western edges of Fallujah largely collapsed early Sunday under a barrage from coalition warplanes, including a single airstrike that killed 47 fighters in the Jolan neighbourhood, said Brig. Haider al-Obeidi of Iraq's special forces.

“From the centre of al-Julan neighbourhood, we congratulate the Iraqi people and the commander in chief ... and declare that the Fallujah fight is over,” al-Saadi told Iraqi state TV, flanked by troops.

Some of the soldiers shot their weapons into the air, sang and waved Iraqi flags.

“The coalition continues to provide support through strikes, intelligence, and advice and assistance to the Iraqi Security Forces operating in Fallujah and will continue to do so through deliberate clearing operations,” said U.S. Army Col. Christopher Garver, the spokesman for the coalition.

Al-Abadi initially declared victory in Fallujah over a week ago, after Iraqi forces advanced into the city centre and took control of a government complex. He pledged that remaining pockets of IS fighters would be cleared out within hours, but fierce clashes on the city's northern and western edges persisted for days.

Iraq's defence minister tweeted that 90 per cent of the city is “safe and inhabitable,” but aid groups are advising the government to exercise more caution.

The U.N. refugee agency said more than 85,000 people have fled Fallujah and the surrounding area since the offensive began. The UNHCR and others have warned of dire conditions in the camps, where temperatures are well over 40 degrees Celsius (104 degrees Fahrenheit) and shelter is limited. Officials have called for more funds to meet mounting needs.

“It is still too early to speak of (civilians returning to Fallujah),” said Karl Schembri of the Norwegian Refugee Council, an international humanitarian organization that does extensive work in Anbar province. UNHCR's representative in Iraq, Bruno Geddo, also said that families are expected to remain in camps “for some time as (Fallujah) is reported to be littered with IEDs” - makeshift bombs and booby traps.

Schembri said clearing away the bombs could take anywhere from days to months.

“We need a thorough de-mining of civilian areas and safety assessments before civilians are given the option to go back,” he said. “The situation in the camps is extremely dire, but we are also not in a position to ensure that people will get supplies and services inside Fallujah either.”

When civilians initially returned to Ramadi after it was declared fully liberated from the militants in February, about 100 people were killed by booby-trapped explosives. The time-consuming de-mining process there is still continuing.

Besides Mosul, IS extremists still control significant areas in northern and western Iraq. The group, which swept across Syria and Iraq in the summer of 2014, declared an Islamic caliphate on that territory. At the height of its power, it was estimated to hold nearly a third of each country.

The campaign for Mosul, which lies some 225 miles (360 kilometres) northwest of Baghdad, has been bogged down by logistics problems as Iraq's political leadership jockeys over the planning of the operation.

Those divisions in the military at times stalled the Fallujah offensive. A similar scenario is expected to play out in the Mosul campaign, because the various groups that make up Iraq's security forces - including Kurdish forces known as the peshmerga - have all vowed to participate in the complex operation.

More than 3.3 million Iraqis have fled their homes since the IS advance, according to U.N. figures. More than 40 per cent are from Anbar province, where Fallujah is located.