BAGHDAD — Breaking a seven-month occupation by the Islamic State, Iraqi troops on Monday retook most of Ramadi, the most populous city in western Iraq, overrunning a government compound held by the terrorist group at the city center and dealing a setback to its deadly grip on large parts of the country.

Iraqi soldiers continued to face stiff resistance by Islamic State fighters in several pockets, and their hold on Ramadi — achieved after a week of fierce fighting with help from American jets that pounded enemy positions — remained tenuous. In Washington, Pentagon officials warned that it would be premature to declare outright victory.

But if the government manages to hold Ramadi, it could prove pivotal to the efforts to beat back the Islamic State in Iraq and, ultimately, to reverse the group’s gains in Syria as well. The Obama administration is hoping that a victory in Ramadi could also help vindicate its strategy of relying largely on air power to aid Iraqi and other partners fighting on the ground.

The Ramadi campaign is the latest in a string of defeats for the Islamic State, also known as ISIS and its Arabic acronym, Daesh. The group has lost as much as 40 percent of the Iraqi territory it conquered last year.