The capture of Sirte means Libya's ruling National Transitional Council (NTC) should now begin the task of forging a new democratic system which it had said it would start after the city, built as a showpiece for Gaddafi's rule, had fallen.
Gaddafi, wanted by the International Criminal Court on charges of ordering the killing of civilians, is in hiding, possibly deep in Libya's southern Sahara desert.
He was toppled by rebel forces on Aug. 23 after 42 years of one-man rule over the oil-producing North African state.
"Sirte has been liberated. There are no Gaddafi forces any more," said Colonel Yunus Al Abdali, head of operations in the eastern half of the city. "We are now chasing his fighters who are trying to run away."
Government fighters hoisted the red, black and green national flag above a large utilities building in the centre of a newly-captured Sirte neighbourhood and celebratory gunfire broke out among their ecstatic and relieved comrades.
"Libya is free from east to west," cried a young fighter Malik Al Gantri, a young fighter from Tripoli who had been in the battle for Sirte for two weeks. "I hope to go home now," he said. "I want to see my mother."
Hundreds of NTC fighters gathered in the centre of Sirte shouting "Allahu Akbar" ("God is greatest"), firing guns into the air and dancing in the streets. One of them, a man aged 65 and blind in one eye, rode around on a mountain bike and carrying an AK47 assault rifle and a Libyan flag.
"This is the best day of my life," said Al Sharash Thawban. "The whole city of Sirte is freed from that criminal Gaddafi."
But a group of about 40 vehicles carrying around 100 Gaddafi loyalists broke out of the siege early on Thursday morning and had headed west, NTC fighters said.
"They broke out just as we were waking up to pray," said Dr Abdul Rauf Mohammad, who was among the NTC troops. "The Gaddafi people broke out west, but the revolutionaries have them surrounded and are dealing with them," said one of the fighters, Abdul Salam Mohammad.
Dozens of NTC pick-up trucks mounted with heavy machine guns raced towards the west in pursuit and the sound of shooting could be heard coming from that direction.
Inside what had been the last redoubt of Gaddafi's men, an area of low-rise apartment blocks known as Neighbourhood Two, was a scene of destruction: gaping holes in buildings, trees stripped of their branches, lamp-posts felled by artillery and traffic lights dangling by their cables.
Reuters saw five dejected-looking Gaddafi prisoners marched down a street, guarded by NTC fighters.
Hundreds of NTC troops have surrounded the Mediterranean coastal town for weeks in a chaotic struggle that has killed and wounded scores of the besieging forces and an unknown number of defenders.
NTC fighters said there were a large number of corpses inside the last redoubts of the Gaddafi troops, but it was not immediately possible to verify the claim.
Thousands of civilians have fled Sirte which had a peacetime population of 75,000 and now lies largely in ruins from the rocket, artillery and tank fire which rained down on the town for weeks.