US Secretary of State Hillary Clinton hailed "Libya's victory" during a visit to Tripoli but fighters loyal to Muammar Gaddafi were still holding out in his home town, underscoring the challenges facing the country's new leaders.
Mrs Clinton is the most senior US official to come to Tripoli since Gaddafi's 42-year rule ended in August.
Her visit was marked by tight security, reflecting worries that Libya's new rulers have yet to establish full control over the country.
After meeting Libya's de facto prime minister, Mahmoud Jibril, she spoke of the need to bring the powerful and heavily-armed regional militias that emerged from the war to oust Gaddafi under central rule.
"We are encouraged by the commitment of the National Transitional Council (NTC) to take the steps necessary to bring the country together," Mrs Clinton said.
"From long experience one factor we know has to happen ... is unifying the various militias into a single military ... Getting a national army under civilian command is essential."
Though the militias express loyalty to the new government, many analysts see them as the biggest threat to Libya's unity.
The United States took part in the NATO bombing campaign that helped Libya's rebels take power, although its aircraft largely played a secondary role to those of Britain and France.
"I am proud to stand here on the soil of a free Tripoli and on behalf of the American people I congratulate Libya," Mrs Clinton said. "This is Libya's moment, this is Libya's victory, the future belongs to you."
NATO reiterated today that its mission was very close to an end but said it was premature to set a timetable for a conclusion of its operations, which alliance officials expect to be announced in coming weeks.
"We are very close to the end, but there are still threats to the civilian population. And as long as these threats persist, we will continue," spokeswoman Carmen Romero told a regular briefing.
Nearly two months since capturing Tripoli, the NTC has stamped out most pro-Gaddafi resistance but has so far failed to capture Sirte, a city on the Mediterranean coast that Gaddafi made into a showpiece for his autocratic rule.
That failure has raised questions about the NTC's ability to exert its authority over the entire country and postponed the launch of its promised democracy programme.
NTC forces were a few days ago poised to declare victory in Sirte, but today they were being forced to retreat in some places and taking intense fire from the dwindling force of Gaddafi loyalists boxed into a small area of the city.
At the eastern end of Sirte's seafront, a Reuters reporter saw the spot where, an hour earlier, mortars had landed in a cluster of NTC fighters.
13 of them were killed in the incident, witnesses said. Blood from one of the victims stained the steps of a nearby house.
In several places in the city, locations that a day earlier were firmly under the control of anti-Gaddafi fighters were too dangerous to access because of fire coming in from loyalists.
On the edge of the "Seven hundred" district, the front line had not moved but the mood of optimism among NTC fighters had been replaced by despair at the mounting casualties.
Sirte is now the last major Libyan town where pro-Gaddafi forces are holding out, after the other bastion of resistance, Bani Walid, fell to the country's new rulers yesterday.
The scenes in Sirte were in contrast to events earlier this week, when Gaddafi loyalists offered little resistance as NTC forces pummelled them with tank fire and mortars.
Libya's new rulers were so confident of their imminent victory in the town that NTC chairman Mustafa Abdel Jalil visited Sirte last week and was greeted by fighters firing triumphantly into the air.
But the NTC offensive - by mostly amateur fighters - has been hampered by a lack of coordination.
Units which converged on Sirte from Benghazi in eastern Libya and Misrata to the west have lost men in "friendly fire" incidents, when they have fired at each other by mistake instead of at the Gaddafi loyalists.
Another frustration for NTC leaders is that Gaddafi, wanted by the International Criminal Court on charges of ordering the killing of civilians, has not been captured. He is in hiding, possibly deep in Libya's Sahara desert.
"We don't know where he is but we hope he can be captured or killed soon, so you don't have to fear him any longer," Mrs Clinton said during a meeting with students at the University of Tripoli. "Then you have to move forward."