Opposition leader Alassane Ouattara calls on President Laurent Gbagbo's troops to desert amid jubilant scenes in Ivory Coast's official capital Yamoussoukro Reuters

Rebels forces fighting to install Ivory Coast's democratically elected president are preparing to advance on the country's largest city, Abidjan, after seizing a key port and the official capital overnight.

Power seems to be slipping away from the incumbent president, Laurent Gbagbo, after troops loyal to his rival, Alassane Ouattara, swept south, taking the official capital, Yamoussoukro, and the port of San Pedro late on Wednesday.

Residents and combatants from both sides said opposition troops are in control and it is now largely calm apart from some sporadic shooting. Now attention turns to Abidjan, where the mood is tense ahead of a possible rebel assault. Ouattara's prime minister, Guillaume Soro, told French radio that Gbagbo has just hours to leave power peacefully.

In a further sign of Gbagbo's weakening position, the Army Chief of Staff sought refuge last night at the home of the South African ambassador to Ivory Coast.

Gen. Phillippe Mangou, his wife and five children arrived at the ambassador's home in Abidjan on Wednesday night, according to the South African foreign ministry.

South Africa says it is consulting with unnamed parties in Ivory Coast, West African regional leaders, the African Union and the U.N. on Mangou's move.

Ouattara's New Forces, renamed the Republic Forces (FRCI), have made huge gains in the past two days, seizing swaths of territory in the centre, east and west.

Seydou Ouattara, a military spokesman, told Reuters: "We have taken the port of San Pedro. Gbagbo's forces have all left. We are in full control."

One San Pedro resident, who declined to be named, said: "Shooting started at around 9pm, then we saw the rebels' vehicles drive into the town. Everyone's staying indoors, but we're still hearing a lot of gunfire."

Witnesses saw soldiers taking off their uniforms and throwing guns and ammunition into ditches as they fled from the rebel army. Others say some soldiers simply switched sides and joined the Republican Forces.

Earlier, residents of Yamoussoukro said they braced themselves for conflict before sporadic gunfire erupted. Serge Kipre, who runs a small clothing store in the city, said: "The night before, we were all calling each other to make sure nobody went outside. In the morning, I saw loads of police with balaclavas and Kalashnikovs racing across town. The market closed, shops shuttered. Everybody seemed on edge."

But the approach of the rebels was eagerly awaited by many young pro-Ouattara supporters, who cheered as they drove by in 4x4s.

Kipre added: "They set a police station ablaze because they felt they would be liberated soon. We are so tired of this situation, we just want them to get it over with."

The capture of Yamassoukro, which is in a pro-Ouattara area, is symbolic but not decisive; it is the capital in name only. Gbagbo's seat of power is in Abidjan – the commercial capital – where fighting has raged for months. But the fall of Yamoussoukro opens up the main road to Abidjan, just 143 miles away.

Earlier this month, a leader of the rebel forces, which have controlled northern Ivory Coast since the 2002-03 civil war, told the Guardian they would "surprise all the analysts" by removing Gbagbo quickly and cleanly.

Such confidence appears to have been borne out so far as the rebels make rapid advances on three fronts and encounter little resistance.

Ally Coulibaly, Ouattara's ambassador to Paris, claimed rebel forces now controlled three-quarters of the country. "President Alassane Ouattara was patient and gave Mr Laurent Gbagbo every possibility to leave power peacefully," he told the French radio station France Inter. "He refused every offer made to him."

Ivorians eventually had to take up arms to avoid a massacre of the civilian population, he added.

On Wednesday, the UN security council imposed travel bans and asset freezes on Gbagbo, who is already under European Union and US sanctions. The resolution also sought to prevent use of heavy weapons in Abidjan.

France's UN ambassador, Gerard Araud, said: "I think the sense of urgency is obvious since … the confrontation is extending in Ivory Coast and the situation is worsening by the hour."

He added the message "is very simple: Gbagbo must go. It is the only way to avoid a full-fledged civil war".