Iraqi forces backed by US-led airstrikes have driven Islamic State (IS) militants out of the centre of the city of Ramadi and seized the main government complex there, military officials said.
However, insurgents are still said to be dug into pockets of the city west of Baghdad.
Ramadi, the provincial capital of the western Anbar province, fell to IS in May, marking a major setback for Iraqi forces and the US-led campaign.
Ramadi and nearby Fallujah, which is controlled by IS, saw some of the heaviest fighting of the eight-year US intervention in Iraq.
In recent months Iraqi forces have launched several offensives to retake Ramadi, but all had stalled.
Iraqi troops began advancing into some parts of the city, located about 80 miles west of Baghdad, earlier this month. But their progress was slowed by snipers, booby traps and the militants' destruction of bridges leading into the city centre.
The heavy fighting and limited access to front-lines made it difficult to follow the troops' progress, and Iraqi officials issued a string of sometimes contradictory statements.
Brigadier General Ahmed al-Belawi said IS militants stopped firing from inside the government complex at around 8am. He added that troops are encircling it as engineering teams clear booby traps.
A few hours later, military spokesman Brig Gen Yahya Rasool announced in a televised statement that Ramadi had been "fully liberated".
But Gen Ismail al-Mahlawi, head of military operations in Anbar, quickly clarified that Iraqi forces had only retaken the government complex and that parts of the city remained under IS control.
He said IS fighters still control 30% of Ramadi and that government forces do not fully control many districts from which IS fighters have retreated.
"The troops only entered the government complex," Gen al-Mahlawi said.
"We can't say that Ramadi is fully liberated. There are still neighbourhoods under their control and there are still pockets of resistance."
Iraqi state TV showed troops, some waving Iraqi flags and others brandishing machine guns, chanting and dancing inside what it described as the government complex.
Soldiers could be seen slaughtering sheep in celebration near heavily damaged buildings.
Col Steve Warren, a US military spokesman in Baghdad, said "today's success is a proud moment for Iraq".
"The clearance of the government centre is a significant accomplishment and is the result of many months of hard work by the Iraqi army, the counter-terrorism service, the Iraqi air force, local and federal police, and tribal fighters," Col Warren said.
He said the US-led coalition has carried out more than 630 airstrikes, in addition to training security forces and providing both advice and equipment to clear bombs and booby traps.
"The coalition will continue to support the government of Iraq as they move forward to make Ramadi safe for civilians to return and as the military moves to fight Isil in other areas of the country," he said, using an alternative acronym for IS.
An Iraqi military officer said militants had retreated from the government complex to other parts of the city. "We were totally surprised today," he said.
"We didn't expect them to retreat from a number of Ramadi areas today, where we entered without any resistance, as if they evaporated."
Brig Gen al-Belawi said the fighters retreated mainly to the eastern areas of Sijariya and Sufiya. There was no immediate word on casualties from the fighting.
The recapture of the government complex should lift the morale of Iraqi forces, who were badly shaken by the fall of the city in May, which came despite months of US-led airstrikes and advances against IS elsewhere in the country.
IS still controls much of northern and western Iraq, which it seized in the summer of 2014, as well as vast swathes of neighbouring Syria. It has declared an Islamic caliphate in the areas under its control and imposed a harsh and violent interpretation of Islamic law.
Ramadi and Fallujah, Sunni Arab cities where distrust of the Shia-led government runs deep, were major bastions of the insurgency in the years after the 2003 US-led invasion.
The capture of Ramadi would be a major victory for Iraqi troops, but would also test the government's ability to heal the country's sectarian divide.