IRBIL, Iraq -- As Iraqi forces advanced toward the al-Salam hospital in Mosul earlier this week, encountering only light resistance from Islamic State fighters, commanders decided to seize the facility instead of sweeping the neighbourhoods along the road leading to it.

A few hours later, as the sun set Tuesday evening, the trap was sprung. First came the suicide car bombs, and then the hospital was surrounded by hundreds of militants firing bursts of heavy machine gun fire and rocket-propelled grenades.

"We thought we were going to die, all we could think about was saving our lives," Pvt. Mithad Abdulzahra of the Iraqi army's 9th Division said later, as he recovered in a hospital bed in the nearby city of Irbil from gunshots that shattered his right arm. The IS fighters eventually fought their way inside the al-Salam hospital. Of the 100 or so Iraqi soldiers trapped there, nearly all were killed or wounded, he said.

Seven weeks into the Iraqi operation to retake Mosul, IS fighters are still contesting every block of Iraq's second largest city, and the battle will likely continue well into next year. The battle for the al-Salam hospital highlights the challenges Iraqi forces face as they move deeper into the city.

"Every time we would fight off one unit of IS fighters, another would appear," said Col. Haider Hatem, who was wounded early on by a sniper's bullet. He said he called in U.S.-led airstrikes but was told that the IS fighters were so close that hitting them from the air would endanger his forces.

Over the next 24 hours, the IS fighters unleashed 15 suicide car bombs.

On Wednesday morning, Iraqi special forces were pulled away from another front in eastern Mosul and tasked with launching a rescue mission. The elite force has served as the tip of the spear in the Mosul offensive, but has also taken heavy losses. The special forces eventually fought their way to the hospital, opening up a route of retreat for the embattled soldiers of the 9th Division.

"When we reached them, they barely had any bullets left," a special forces officer said on condition of anonymity because he was not authorized to brief reporters.

As Iraqi forces retreated, U.S.-led warplanes hit both the hospital and the abandoned Iraqi army vehicles. IS often uses hospitals as bases to fire on Iraqi troops. The coalition says it is reluctant to strike them for fear of damaging vital infrastructure.

Col. John Dorrian, a coalition spokesman, said the strike was carried out at the request of Iraqi ground forces and the hospital was hit because IS fighters were using it to fire down on Iraqi troops.

In all, more than 20 Iraqi soldiers were killed in the battle, and a handful of armored Iraqi vehicles were captured by IS, the special forces officer said. An IS video posted online Thursday showed what appeared to be about a dozen destroyed Iraqi army vehicles near the al-Salam hospital. The video could not be independently verified.

The battle for the Mosul is the biggest operation Iraq has carried out since the 2003 U.S.-led invasion, and comes just two years after Iraqi forces crumbled in the face of the lightning IS advance in the summer of 2014.

Iraqi forces have retaken a number of cities and towns over the past year, but few units have experience in urban combat. The 9th Division is an armored force, designed for conventional battles against other armies on open terrain. Iraq's special forces are better equipped for the street battles in Mosul, but there aren't enough of them to retake the city on their own.

Abdulzahra, the soldier who was hospitalized after the battle, says he doesn't believe his commanders will learn from their missteps. "Of course these mistakes will keep happening," he said. "They happen every time."