The end of Colonel Muammar Gaddafi's 41 years in power appears to be in hand with the rebels in Tripoli.
Although the old regime still has the men and the material to draw out the conflict, its supporters may decide there is no reason to die for a lost cause.
The circumstances in which Gaddafi's regime falls is important for the future of Libya. Will he himself flee, disappear to fight again, be arrested or die in the last ditch? Will his supporters be hunted down and killed?
After a civil war lasting six months, a stable peace means that those who fought for him should not be treated as pariahs to be slaughtered, arrested, threatened with reprisals or politically marginalised.
For if Gaddafi proved too weak to stay in power, this does not mean that the rebels have overwhelming strength. They were saved from defeat last March by Nato aircraft striking at Gaddafi's armour as it advanced on Benghazi. They entered Tripoli only because they received tactical air support from Nato.
It is an extraordinary situation. The Transitional National Council (TNC) in Benghazi is now recognised by more than 30 foreign governments, including the US and Britain, as the government of Libya. But it is by no means clear that it is recognised as such by the rebel militiamen who are seizing the capital.
The rebel fighters in Misrata, who fought so long to defend their city, say privately they have no intention of obeying orders from the TNC. Their intransigence may not last but it is one sign that the insurgents are deeply divided.
It is not the only sign. The rebels' commander-in-chief General Abdul Fattah Younis was murdered only weeks ago after being lured back from the front, parted from his bodyguards and then, by many accounts, tortured to death and his body burned. The TNC has since sacked the provisional Cabinet for failing to investigate his death properly, the sacking coming apparently because Younis's Obeidi tribe was demanding an explanation for his death.
For many Libyans the end of Gaddafi's long rule will come as an immense relief. His personality cult, authoritarian regime, puerile ideology and Gilbert-and-Sullivan comic opera antics created a peculiar type of oppression. Libyan students would lament that they had to redo a year's studies in computer science or some other discipline because they had failed an obligatory exam on Gaddafi's Green Book. Not surprisingly, the building which housed the centre for Green Book studies was one of the first to be burned in Benghazi when the uprising started on February 16, two days earlier than planned by its organisers.
The naive nationalism of Gaddafi and the young officers around him who overthrew the monarchy in 1969 astonished other Arab leaders. But the new regime did succeed, by squeezing Occidental, in raising the price of oil with dramatic consequences for Libya and the rest of the Middle East.
Libyans enjoyed a far higher standard of living than their neighbours in Egypt or the non-oil states. But for all Gaddafi's supposed radicalism, his regime in its last decade was quasi-monarchical, with his sons taking a great share of wealth and power.
The fact that Libya is an oil producer close to Europe helps explain why many leaders and states which fawned on Gaddafi only a year ago now denounce him as a tyrant and recognise the shady men who make up the rebel high command as the leaders of the new Libya. .
It is evident that Gaddafi has lost but it is not quite so clear who has won. France and Britain, crucially backed by the US, initially intervened for humanitarian reasons, but this swiftly transmuted into a military venture to enforce a change of regime. Once committed it was never likely that Nato would relent until Gaddafi was overthrown. The rebel columns of pick-ups filled with enthusiastic but untrained militia fighters would have got nowhere without tactical air support blasting pro-Gaddafi forces. Given Nato air support, it is surprising the struggle has gone on so long.
If Nato put the rebels into power will it continue to have a predominant role on what happens next in Libya?
It is worth recalling that Saddam Hussein was unpopular with most Iraqis when he fell in 2003, as were the Taleban in Afghanistan in 2001. But in neither case did this mean that there was an opposition which had the support to replace them. In both countries wars thought to be over burst into flame again. Foreign allies were seen as foreign occupiers.
In Libya the rebels have triumphed, but foreign intervention brought about the fall of Gaddafi just as surely as it did Saddam and the Taleban. In fact he resisted longer than either and the war was fiercer and more prolonged than France and Britain imagined. It is clear Gaddafi will go, but we still have to see if the war is truly over.