A frame grab from a video released on Aug. 3 by a Syrian Kurdish activist media group shows a fighter from the U.S.-backed Syrian Democratic Forces firing his weapon during clashes with the Islamic State in Raqqa. (Hawar News Agency/AP)

For three years, the Syrian city of Raqqa was the Islamic State’s greatest stronghold, featuring heavily in propaganda and providing a launchpad for attacks carried out around the world.

But district by district, the city is now emptying out as U.S.-backed forces inch their way through the extremist group’s self-proclaimed capital in Syria. The two sides are locked in a grinding battle of attrition that ranks among the toughest chal­lenges to date for the anti-Islamic State coalition.

Thousands of civilians are believed to have fled Raqqa in recent weeks, often with smugglers under the cover of darkness. It is a perilous escape through the city’s narrow streets as the militants dispatch bombers among those fleeing.

“The battle for Raqqa is completely different from anything we have fought before. ISIS is defending its capital now,” said Mustafa Bali, a spokesman for the Kurdish-dominated militia — known as the Syrian Democratic ­Forces, or SDF — that Washington has backed in the fight.

Previous offensives have ended when the militants retreated in an apparent effort to conserve manpower ahead of more consequential battles. This time, Bali said, there would be no escape. 

A Syrian Democratic Forces fighter runs in front of a damaged building in Raqqa on July 27. (Hussein Malla/AP)

“Raqqa is completely surrounded,” he said. “They are fighting to the death.”

Col. Ryan Dillon, a spokesman for the U.S.-led coalition in Iraq and Syria, said last week that after two months of heavy fighting, the SDF­ holds 45 percent of Raqqa.

While the Pentagon insists that its proxy force is making daily progress backed by U.S. airstrikes, the Islamic State is booby-trapping houses and sending waves of suicide bombers to ensure that the units pay for each foot of ground. Unlike Iraqi forces­ that cleared the far larger city of Mosul with tens of thousands of troops and reserves as backup, the SDF has significantly fewer fighters and less heavy equipment.

Reports of civilian casualties from the SDF and coalition efforts are mounting. The United Nations and nonprofit monitoring groups say hundreds have died, although a final toll is unlikely to ever be known.

Brett McGurk, U.S. special envoy for the coalition, said Sunday that about 2,000 Islamic State fighters remain in the city and “most likely will die in Raqqa.”

Estimates of the number of people remaining in the city vary. The Reach Initiative, a nonprofit survey group, has put the number at between 10,000 and 25,000. According to its latest research, 14 of Raqqa’s 24 neighborhoods, most on the eastern and western fringes of the city, are almost or completely deserted.

A man and woman flee Raqqa on July 31. (Rodi Said/Reuters)

Doctors Without Borders said last week that its medics treated more than 400 wounded civilians, many of whom were injured by sniper fire or land mines on their way out.

Pediatricians working at internationally supported clinics and displacement camps say they are witnessing signs of shock more severe than anything in their medical careers.

“I've never seen 2-year-olds who didn’t fight the doctor examining them. But these children did nothing; they just lay there as if it was surrender,” said Rajia Sharhan, a doctor with the U.N. children’s agency, UNICEF.

Aid groups have warned that three years under Islamic State control could have far-reaching consequences for children who do escape.

“What you see in their eyes is shock. They’ve survived the bombing and shelling. They’ve been bound to their mother’s chest on the escape and heard the screams over and over. They have already lost their childhood,” Sharhan said.

For those who remain in the city, access to food is critically limited as prices­ skyrocket and daily air­strikes make trips to the market a terrifying prospect.

Residents say their kitchen shelves fill up only when neighbors flee. A media activist who goes by the nom de guerre Tim Ramadan said the family next door handed him their house key as a parting gift and told him to eat. 

Inside he found moldy bread, olives, thyme and dried noodles. “I hadn’t eaten for days,” he said.

State Department officials estimate that it will take months, if not years, to clear Raqqa of unexploded munitions and booby traps after the Islamic State is routed. Much as it did in Mosul, the terrorist group probably has perfected its ability to conceal and plant mines and other devices that will maim and kill people long after the battle is over. 

Explosives have been hidden inside doorways, generators and even ­corpses.

Dillon, the coalition spokesman, said that 80 percent of the attacks on the Syrian Democratic ­Forces have come from improvised explosive devices, some of which are rigged to collapse entire homes after fighters enter.

The offensive has intensified pressure on the Islamic State as it defends what remains of its self-declared caliphate. In Iraq, the group lost control of Mosul last month after a nine-month battle that destroyed swaths of the city it left behind.

In its Syrian territory, the militants appear to be facing growing manpower problems. Photographs shared on social media last week showed an Islamic State communique announcing mandatory conscription for 20- to 30-year-old men in and around the eastern city of Deir al-Zour.

That raises the prospect that many of the area’s remaining tens of thousands of civilians could be coerced into becoming military targets for the SDF and the U.S.-led coalition.

In a WhatsApp message sent late Saturday, a 25-year-old said he was scared of what would follow. “We have less than a week to escape from here,” he said. “Otherwise we will be taken by force.”

Gibbons-Neff reported from Washington. Zakaria Zakaria in Istanbul contributed to this report.