BAGHDAD — Iraqi forces said Sunday that they had captured the main government compound in Ramadi, a symbolic win in a key city that has been under Islamic State control for seven months.

Engineering teams were still working to clear explosive devices in the area, but the complex was entirely under the control of Iraqi forces, military commanders said. Still, much of the city’s downtown remains in the hands of the militants, officials said.

Backed by a barrage of U.S. airstrikes, Iraqi forces have been making steady progress in the western city in recent weeks, but they have been slowed by booby traps and by efforts to avoid civilian casualties.

The battle for Ramadi, about 80 miles west of Baghdad, is a significant test for Iraqi forces, which collapsed during an assault by the militants in May. The city was the scene of some of the fiercest fighting for U.S. forces during the Iraq war in street battles with Islamic State’s predecessor, al-Qaida.

Although it holds limited strategic value, the government compound is in the heart of the city’s downtown and houses its administrative buildings.

“The compound has been liberated,” said Suhaib al-Rawi, the governor of Anbar province, of which Ramadi is the capital. He said Iraqi forces were now advancing from the south and west to close in on the remaining militant-held neighborhoods.

Sabah Noori, a spokesman for the Iraqi special forces, confirmed that counterterrorism forces had taken control of the complex.

There was a celebratory atmosphere in Baghdad, where state television showed images of people dancing and letting off fireworks as they waved the Iraqi flag in the streets.

Some Iraqi commanders have said that they expect Ramadi to be entirely back under their control by the end of the year, but large neighborhoods are yet to be secured.