After days of shelling by Iraqi forces, some 200 residents decided to take their chances and flee from one of the last pockets of Mosul controlled by the Islamic State group. They made it as far as a nearby hospital before militant snipers opened fire from the roof, mowing them down by the dozens.

Their harrowing flight, recounted by survivors, illustrates the dangers that residents of Iraq’s second largest city have faced throughout months of heavy fighting as Iraqi forces, backed by a U.S.-led coalition, struggle to drive the militants out.

Many have found themselves caught in the crossfire, with Iraqi artillery and coalition airstrikes on one side, and militants determined to use them as human shields or punish them for leaving on the other.

Riyadh Abdullah (21), said he and his family, along with about 200 neighbors, had decided to leave their homes last Thursday after days of heavy shelling. As they neared the hospital, gunmen fired down on them, shooting him in the leg and hitting several others. Iraqi troops nearby then opened fire at the militants.

“There were bullets falling on us like rain,” he said from a hospital bed in the Kurdish regional capital, Irbil.

“For two days there were kids bleeding, no food, no water, under the sun. So the majority died. Nobody came to us. We were shouting but no one came,” he said.

Jassem Mohammed (17), was also among those who were hit. He said 12 members of his family, including two uncles, an aunt, and his two grandfathers, were gunned down around him.

“I was also hit but it wasn’t that bad, I wasn’t bleeding. Then, that afternoon, I was hit again by a sniper in the side and then I started to bleed,” he said.

“I was trying to lift my left leg and crawling on my hands. We crawled for three or four minutes and then rested for five minutes. And then crawl and crawl again. We kept crawling until we reached the army,” he said.

David Eubank, an American medic who works in a field clinic near the front line, said he managed to save two civilians a day after the shooting by getting the Iraqi army to drive a tank onto the road for cover. He said he dragged another five people to safety the following day. Coalition warplanes aided the rescuers by dropping smoke bombs to obscure their movements, he added.

Dr. Eubank said his clinic treated about 40 people with gunshot wounds from among those who managed to make it across the road to the Iraqi-controlled area.

There are conflicting reports as to how many people died. Zeid Ra’ad Al Hussein, the U.N. human rights chief, said in Geneva on Tuesday that “at least 163” people were shot and killed, and more were missing.

Both Mr. Abdullah and Dr. Eubank said that they had seen about 50 people lying on the ground. Col. Hussein Mustafa, the commander of the Iraqi army brigade in the district, estimated that around 150 people were killed.

The area remains inaccessible because of heavy clashes.

Iraqi forces have retaken most of Mosul since the offensive began in October, but victory has come at a staggering cost, with heavy casualties among troops and civilians, and hundreds of thousands forced to flee.

“It’s all because of the shelling,” said Ahmed Najm (27), who is recovering in the Irbil hospital from a shrapnel wound. He said he lost 13 family members in the shooting.

“The people saw this intensive shelling, this destruction, and so they all left their homes. And that’s what caused the massacre,” he said.