© ISSOUF SANOGO/AFPIvory Coast's main city of Abidjan saw forces loyal to Gbagbo patrolling as rebel forces approached.
Laurent Gbagbo faces bloody overthrow as he loses general and rebels advance on main city of Abidjan

Ivory Coast's president, Laurent Gbagbo, faces being overthrown after his top general deserted him and rebel forces advanced into Abidjan, his seat of power.

Heavy weapons and machine gun fire were heard in the centre of Ivory Coast's main city. French troops were deployed as the four-month political crisis appeared to near its endgame, with the opposition claiming Gbagbo had only hours left in power.

Presidential claimant Alassane Ouattara's government ordered the closure of Ivory Coast's land, air and sea borders, Reuters said.

Ouattara's government previously ordered a curfew, and two sources said forces loyal to Gbagbo had ceded control of Abidjan's airport to UN peacekeepers.

State television, which has remained loyal to Gbagbo, has gone off air following hours of fighting near its headquarters in Abidjan. Residents across the city said the broadcaster stopped transmitting at 10.45pm GMT after repeatedly showing images of Gbagbo and his close entourage.

It was not immediately clear what caused the cut in transmission but forces loyal to Ouattara were fighting Gbagbo loyalists near the station's headquarters in the Abidjan neighbourhood of Cocody.

Ivorian sources in South Africa reported rumours that Gbagbo could be about to step down, possibly turning to South Africa for a diplomatic channel to end his 10-year rule. Officials in Pretoria denied there had been an approach.

The speculation was begun by the departure of Phillippe Mangou, Gbagbo's army chief of staff, to take refuge with his wife and five children at the South African ambassador's residence in Abidjan.

"We've seen a regime collapse," said one western diplomat, who could hear gunfire from his residence. "The army is no longer an effective body. It has defected and deserted, and has no leadership now the general has gone into hiding."

He added: "There's very little to keep Gbagbo in power and he must know it. I just hope he's not one of those men who fight to the death, because it will be a bloodbath."

Rebels fighting to install Ouattara as president have swept hundreds of miles over three days. On Wednesday they took the official capital, Yamoussoukro, doing a victory lap in vehicles as people cheered and clapped, and the seaport, San Pedro. But aid workers estimated that the casualties ran into thousands.

Ouattara is the internationally recognised winner of last November's election. He said the rebels will "re-establish democracy and enforce the choice of the people". There were reports of Gbagbo's troops downing weapons and uniforms, and in some cases going to join Ouattara at the UN-protected Golf hotel.

Ouattara's prime minister, Guillaume Soro, told French radio that a government of national unity was still possible if Gbagbo stepped aside in the "coming hours", but otherwise it would be "winner takes it all". Later, Soro said that Gbagbo had only two or three hours left in power and that the "game is over".

Officially there was defiance from Gbagbo, a Sorbonne-educated professor who in 2004 defended his inability to control rioting mobs by asking: "When the French were looking for Louis XVI to cut his head off, would it have been fair to ask him if he controlled the streets?"

Members of Gbagbo's guard were deployed near the presidential palace in the Plateau area. Analysts say a core of 2,500 troops might be willing to fight to the end. A Gbagbo adviser, Toussaint Alain, suggested the president was prepared to make a last stand. "He will not resign in the wake of this attack," he told the Associated Press. "He is not going to abdicate. He is not going to lay down his arms.

"He will stay in power to lead the resistance to this attack against Ivory Coast organised by France, the United States and the United Nations."

Abidjan was a war zone on Thursday. The streets were deserted. Foreign nationals had been advised to stock up with five days of food and water.

Salvatore Sagues of Amnesty International said Abidjan was "on the brink of a human rights catastrophe and total chaos. Cote d'Ivoire is facing a major humanitarian crisis. The international community must take immediate steps to protect civilians."

Jacques Seurt, of the International Organisation for Migration in Ivory Coast, said: "You can't go out in Abidjan. We can hear shooting outside, close to a big military camp and the state TV station. There is no way to get out to reach a safe haven. It's too dangerous. I think the Forces Nouvelles [pro-Ouattara rebels] are coming into Abidjan. After the capture of the town, I'm afraid there will be a lot of looting."

Reuters said soldiers from the 1,000-strong French Licorne force in Ivory Coast had been deployed in the south of the city. A western military source said others were sent to rescue French nationals attacked in the Deux Plateaux neighbourhood by youth supporters of Gbagbo.

Rebels in control of several northern districts of the city attacked a prison and freed the inmates, a rebel commander said. The rebels also advanced into Yopougon, a district of Abidjan that fervently supports Gbagbo, according to witnesses.

Advancing on foot, the rebels reportedly set up roadblocks on one of Yopougon's main thoroughfares and battled with police. In the predominantly pro-Ouattara Adjame district, several residents reported firing by pro-Gbagbo militiamen. A close aide to Ouattara said of the rebels: "They will enter the city on multiple fronts, from multiple directions."

Overnight, the rebels also took Gbagbo's home town, the village of Mama, where the former president had a villa, the aide told AP. "The rebels slept in Gbagbo's bed," he added.

At least 462 people have died and up to 1 million have fled their homes. The true figure is likely to be much higher. Pierre Kraehenbuehl, of the International Committee of the Red Cross, told a press conference in Geneva: "Casualty numbers, killed and injured, is running into the thousands. That is our indication."

The rebels have controlled northern Ivory Coast since the 2002-03 civil war effectively split the country in two.