A lightning offensive that ousted the Islamic State from one of its last strongholds in Iraq reflects vast improvements in Iraq’s security forces and a demoralized enemy, U.S. and Iraqi officials said Monday.

The success of the offensive in Tal Afar on Sunday also highlights a growing level of cooperation among armed factions in Iraq, said Lukman Faily, a former Iraqi ambassador to the United States. Government-sanctioned Shiite militias helped isolate the area while Iraq’s military thrust into Tal Afar, which is about 50 miles west of the recently liberated city of Mosul.

Faily called the victory a significant "morale booster" for Iraq's government.

The collapse of the terror group's defenses in Tal Afar marks a milestone in a U.S.-aided campaign to free the last remaining Iraqi territory held by the Islamic State, also known as ISIS, more than three years after the militants invaded the country from neighboring Syria.

Iraqi forces launched the offensive Aug. 20 on five different fronts, rapidly overwhelming the ISIS fighters. “It went very quickly,” said U.S. Army Col. Ryan Dillon, a coalition spokesman. “We went into this planning for the worst.”

Few civilians remained in the city, which allowed Iraq’s security forces to advance quickly against militants attempting to defend the area, the coalition said. The pace of the campaign was in contrast to the offensive to liberate Mosul, a much larger city. That effort took nine months because tens of thousands of Iraqi civilians were trapped and often used as human shields by ISIS.

Iraq’s military, which announced Sunday that Tal Afar had been “liberated,” was still clearing numerous pockets of resistance north of the city.

In 2014, ISIS militants swept into Iraq, capturing Mosul, the country’s second-largest city, as well as Ramadi and Fallujah, important Sunni cities in western Iraq.

At the time, the militants controlled a large chunk of the country, the capital Baghdad was at risk of falling into ISIS' hands, and Iraq’s military was in disarray.

Since then, Iraqi forces have been rebuilt with the help of U.S. arms and equipment and coalition trainers and advisers. Airstrikes by a U.S.-led coalition have increased as Iraqi ground forces made progress against militants in key cities.

Iraq's reconstituted military showed progress by recapturing Ramadi and Fallujah last year.

Threats posed by ISIS remain, as evidenced by a car bomb Monday in eastern Baghdad that killed at least 12 people. The Islamic State claimed responsibility for the attack. As the group loses ground, it has resorted to terror attacks.

Several thousand militants remain in a string of remote villages in western Iraq along the Euphrates River Valley, which extends into Syria. Recapturing the area is critical to gain control over the border, Faily said.

Militants also hold Hawija, a town in northern Iraq, with about 1,000 fighters, according to the coalition. As long as the militants hold Hawija they can threaten Kirkuk, a major city east of the town.

Coalition airstrikes have begun ramping up attacks in the remaining ISIS strongholds in Iraq over the past week. A decision on when to launch ground operations in those areas will be made by Iraq’s government, the coalition said.

The Pentagon's initial plan when it launched airstrikes and sent advisers to the region was to make Iraq the main battlefield against ISIS.

Now efforts have gained momentum to drive them from Syria, where a civil war has raged for more than six years. A U.S.-backed force of Kurds and local Arab militias are fighting to recapture Raqqa, the Islamic State’s de facto capital in Syria.

The coalition faces tough fighting there, where about half the city has been cleared of militants after several months of fighting, the coalition said.

The city is defended by an estimated 2,000 militants who have spent years preparing elaborate defenses, including concrete reinforced tunnels and bunkers.

“They are going to fight to the end in Raqqa, just like they did in Mosul,” Dillon said.

More:U.S.-led Iraqi forces launch battle for Tal Afar

More:ISIS is rapidly losing control of Raqqa, its headquarters in Syria

More:Fight against ISIS 'far from over' despite terrorist group's loss of Mosul

More:Desperate ISIS fighters using human shields as battle nears end in Mosul