Emboldened rebels laid siege to Colonel Muammar Gaddafi's compound in central Tripoli last night as Libya's fight to break free of 42 years of dictatorship looked on the brink of a success after a six-month struggle that at times looked doomed to plunge the country into a prolonged civil war.

Opposition leaders warned that victory could only be assured when the belligerent dictator was in rebel hands, but their swift advance into Tripoli and the capture of three of Gaddafi's sons was enough to spark euphoric celebrations early yesterday in Green Square, the symbolic heart of the Gaddafi regime.

But the jubilation subsided somewhat as Gaddafi forces carried out a series of ambushes before launching an assault yesterday afternoon. Remnants of regime troops drove out the rebel fighters during running battles in the capital. The harbour, as well as Green Square, saw prolonged clashes, with both sides using heavy weaponry in the built-up areas. The electricity sub-station for the area was damaged after being targeted by regime mortar fire.

As the fighting intensified last night, Nato's Apache helicopter gunships were forced into action once more, despite Tripoli being supposedly liberated by the rebels and after the opposition administration, the Transitional National Council (TNC), declared that the Alliance's military action was no longer necessary.

"There are obviously pockets of Gaddafi men whom we had not been aware of," said Yusuf Bin Daroush, a rebel commander. "They are trying to disrupt our attempts to bring peace to the city. They are using mortars and machine guns and causing civilian casualties."

There were prolonged clashes at Bab al-Aziziya, Gaddafi's complex, amid speculation that he was still there. One rebel fighter, Mohammed Kamlish, said: "He may be directing operations from there. He is trying to cause as much damage as possible before the end. He is a man who can only destroy."

Such fighting tempered claims that rebels now hold up to 90 per cent of Tripoli. Many neighbourhoods resembled ghost towns, the shops shuttered, the residents long gone, abandoning their homes in fear of a bloodbath.

Rebel checkpoints sprang up across the city, but certain areas were still very much under regime control, with journalists in the central Rixos Hotel reporting that trucks loaded with anti-aircraft guns were stationed outside. Contrary to earlier reports of his capture, Saif al-Islam Gaddafi, the Libyan leader's son and the public face of the Gaddafi regime overseas, arrived outside the hotel late last night. One journalist reportedly asked Saif al-Islam if his father was safe and in Tripoli, to which he replied: "Of course".

His arrival came after the Libyan government spokesman Moussa Ibrahim told pro-Gaddafi TV station Al-Urubah that Gaddafi's sons were doing well. Mr Ibrahim contradicted rebel claims that they controlled most of Tripoli, saying "80 per cent of Tripoli is under complete control". He added: "The Libyan leader is steadfast, he is in Libya, leading the battle himself. We are under his command. His sons are in Libya as well, fighting and giving their blood."

Despite the lightning advance late Sunday into Tripoli that was supported by rebel sleeper cells, Colonel Gaddafi appeared to have had enough warning to slip into hiding. His whereabouts remained a mystery last night, with the opposition leader, Mustafa Abdul Jalil, telling a news conference the hunt had so far been unsuccessful. "Bab al-Aziziya and the surrounding areas are still out of our control... we have no knowledge of Gaddafi being there, or whether he is still in or outside Libya," he said.

Colonel Gaddafi's fighters appeared capable of repelling rebel forces from the heavily fortified compound, with tanks rolling out early yesterday and opening fire on opposition fighters trying to force their way in. Late in the evening, Al-Arabiya television, citing a rebel spokesman, reported that Nato had targeted the compound with air strikes. Battles continued outside the command centre all day, with residents reporting explosions and gunfire. Rebels put the death toll in the capital at around 370, while the government claimed that 1,300 people had been killed.

From the city of Sirte, the centre of Colonel Gaddafi's support, forces loyal to the Libyan leader fired a suspected Scud missile, a US defence official said last night.

As the fighting raged, world leaders joined the rebel chorus calling on Colonel Gaddafi to go, with US President Barack Obama saying the dictator and his regime "need to recognise that their rule has come to an end".

There were reports that even elements within the inner circle were defecting, with the Prime Minister Baghdadi al-Mahmoudi reported to be in Tunisia as the military balance appeared irreversibly weighed against them. There were also reports one of Colonel Gaddafi's sons, Mohammed, had been captured yesterday. But late last night, Libya's US ambassador Ali Suleiman Aujali said Mohammed had escaped from the hands of the rebels, and was now missing.

Last night, Al-Jazeera reported that two bodies had been found in Tripoli, with some unconfirmed reports suggesting they belonged to Abdullah al-Senussi, the intelligence chief, and Khamis Gaddafi, another son and chief of the feared Khamis Brigade. The state television building also fell into rebel hands, denying Colonel Gaddafi the mouthpiece that for decades had broadcast his propaganda.

A Nato spokesperson vowed it would continue its attacks until all pro-Gaddafi elements had thrown down their weapons. Warplanes have hit more than 40 targets in and around Tripoli in the last few days. Without their support, the rebels would have struggled to break out of the eastern stronghold they swiftly seized in February. Since then they have largely been operating out of their de facto capital, Benghazi.

Despite air strikes and Western military advisers on the ground, the rebels based in the east appeared ramshackle, ill-prepared and badly organised by a troupe of military commanders with varying degrees of experience. Factions in the west held out in the besieged city of Misrata for weeks as the rebels in the east beat a retreat from key coastal towns. They consolidated to lead the final push on Tripoli.

With splits already emerging between rival regional groups and between Islamists and other members of the anti-Gaddafi alliance, many analysts have warned of a protracted period of instability.

Libyan reaction

* Mustafa Abdul Jalil, head of the Transitional National Council

"[Libya is] on the threshold of a new era... of a new stage that we will work to establish the principles that this revolution was based on, which are freedom, democracy, justice, equality and transparency... the real moment of victory is when Gaddafi is captured"

* Nouri Mohammed, opposition fighter in Tripoli

"We haven't been able to launch an attack [on Bab al-Aziziya, Gaddafi's compound]. We are waiting for more men and heavy weapons. They are defending it... those inside are soldiers, volunteers, hardline supporters of the state."

* Mahmud Nacua, Charge D'Affaires for Libya in London

"Nato has done a very good job, they neutralised Gaddafi's war machine... but I think their role will be over and the Libyan people will independently rebuild their country... the fighters will turn over every stone to find [Gaddafi] to arrest him and to put him in the court."

Where's Gaddafi? the mystery deepens

* As the rebels went from street to street in Tripoli yesterday, one goal was at the forefront of their minds: to find the man they blame for running their country into the ground and sowing misery and fear during his 42-year rule.

What happens when they find Muammar Gaddafi remains to be seen. Victor's justice can be swift, harsh and deadly. But the rebels may well concede to international demands to take him into custody, either trying him in Libya, sending him to the International Criminal court, or – a more unlikely scenario – letting him go quietly into exile in the interests of national reconciliation.

First, they have to find the eccentric Colonel. Rumours about his whereabouts have been circulating since the Nato bombardment started in March. Usually, after a flurry of speculation, he would turn up taking a walk around a Tripoli park or engaging in a rambling rant to an adoring crowd.

Since the rebels converged on Tripoli on Sunday night, the rumours have intensified. Despite his vow that he would die in Libya, there were reports that his family was moving money and other assets out of the country. Then it was suggested he had fled to neighbouring Algeria or, more far-fetched, South Africa.