Rebel fighters swept into the heart of Tripoli and crowds took to the streets to celebrate what they saw as the end of Muammar Gaddafi's four decades of power, but a government fightback was reported as dawn broke on Monday.
Tanks emerged from Gaddafi's stronghold in the center of the Libyan capital and were shelling the area, Al Jazeera television reported.
Despite euphoria among rebels and their backers in Tripoli and elsewhere, a rebel spokesman, identified on Al Jazeera as Nasser, said government troops still controlled "about 15 to 20 percent of the city."
Earlier, rebels waving opposition flags and firing into the air drove into Green Square, a symbolic showcase the government had until recently used for mass demonstrations in support of the now embattled Gaddafi. Rebels immediately began calling it Martyrs Square.
Two of Gaddafi's sons were captured by the rebels, but the whereabouts of Gaddafi himself were unknown.
U.S. President Barack Obama said Gaddafi's rule was showing signs of collapse and called on him to quit now to avoid further bloodshed.
Laila Jawad, 36, who works at a Tripoli nursery, told Reuters: "We are about to be delivered from the tyrant's rule. It's a new thing for me. I am very optimistic. Praise be to God."
The rebels made their entrance into the capital driving in convoy through a western neighborhood.
Remaining defiant, Gaddafi earlier had made two audio addresses over state television calling on Libyans to fight off the rebels.
"I am afraid if we don't act, they will burn Tripoli," he said. "There will be no more water, food, electricity or freedom."
But resistance to the rebels initially appeared to have largely faded away, allowing the rebels and their supporters to demonstrate in Green Square.
Libyans kissed the ground in gratitude for what some called a "blessed day."
Near Green Square youths burned the green flags of the Gaddafi government and raised the rebel flag. One rebel fighter from the Western mountain said: "We are so happy -- we made it here without any problems."
Many Tripoli residents received a text message from the rebel leadership saying: "God is Great. We congratulate the Libyan people on the fall of Muammar Gaddafi."
Gaddafi, a colorful and often brutal autocrat who has ruled Libya for more than 40 years, said he was breaking out weapons stores to arm the population. His spokesman, Moussa Ibrahim, predicted a violent reckoning by the rebels.
"A massacre will be committed inside Tripoli if one side wins now, because the rebels have come with such hatred, such vendetta ... Even if the leader leaves or steps down now, there will be a massacre."
Obama, on vacation in the island of Martha's Vineyard, said in a statement: "The surest way for the bloodshed to end is simple: Muammar Gaddafi and his regime need to recognize that their rule has come to an end. Gaddafi needs to acknowledge the reality that he no longer controls Libya. He needs to relinquish power once and for all."
NATO, which has backed the rebels with a bombing campaign, said the transition of power in Libya must be peaceful.
TRIPOLI FALLS QUICKLY
After a six-month civil war, rebels moved quickly into Tripoli, with a carefully orchestrated uprising launched on Saturday night to coincide with the advance of rebel troops on three fronts. Fighting broke out after the call to prayer from the minarets of the mosques.
Rebel National Transitional Council Coordinator Adel Dabbechi confirmed that Gaddafi's younger son Saif Al-Islam had been captured. The International Criminal Court in The Hague, which wants Saif along with his father on charges of crimes against humanity, confirmed he had been held and said he should be handed over for trial.
Gaddafi's eldest son Mohammed Al-Gaddafi had surrendered to rebel forces, Dabbechi told Reuters. In a television interview, the younger Gaddafi said gunmen had surrounded his house, but he later told al-Jazeera in a phone call that he and his family were unharmed.
Only five months ago Gaddafi's forces were set to crush the rebel stronghold of Benghazi, the leader warning then that there would be "no mercy, no pity" for his opponents. His forces, he said, would hunt them down "district to district, street to street, house to house, room to room."
The United Nations then acted quickly, clearing the way for creation of a no-fly zone that NATO, with a campaign of bombing, used ultimately to help drive back Gaddafi's forces.
"It's over. Gaddafi's finished," said Saad Djebbar, former legal adviser to the Libyan government.
In Benghazi in the east, thousands gathered in a city-center square waving red, black and green opposition flags and trampling on pictures of Gaddafi as news filtered through of rebel advances into Tripoli.
Mohammed Derah, a Libyan activist in Tripoli, told Al Jazeera: "This is another day, a new page in Libya's history. We are witnessing a new dawn and a new history of freedom. The regime is finished."
"We are living historic moments, moments that we haven't witnessed since we were born, since we came out of our mothers' wombs," said We'am Mohanna.
Celebratory gunfire and explosions rang out over the city and cars blaring their horns crowded onto the streets. Overhead, red tracer bullets darted into a black sky.
"It does look like it is coming to an end," said Anthony Skinner, Middle East analyst, Maplecroft. "But there are still plenty of questions. The most important is exactly what Gaddafi does now. Does he flee or can he fight?"
"In the slightly longer term, what happens next? We know there have been some serious divisions between the rebel movement and we don't know yet if they will be able to form a cohesive front to run the country."
Gaddafi, in his second audio broadcast in 24 hours, dismissed the rebels as rats.
"I am giving the order to open the weapons stockpiles," Gaddafi said. "I call on all Libyans to join this fight. Those who are afraid, give your weapons to your mothers or sisters.
"Go out, I am with you until the end. I am in Tripoli. We will ... win."
A Libyan government official told Reuters that 376 people on both sides of the conflict were killed in fighting overnight on Saturday in Tripoli, with about 1,000 others wounded.