For months, rebels fighting to oust Libyan leader Moammar Gaddafi have been predicting the fall of the capital, Tripoli. Now, after weeks of significant gains, they have begun talking openly about plans to maintain security if he is deposed.

The rebels say they are determined to avoid the kinds of looting and killing that took place in Baghdad after the 2003 U.S. invasion of Iraq. Convinced that Gaddafi’s fall is inevitable, they have sought the help of international military officials and politicians on plans to avoid similar disorder in Tripoli.

Internal divisions and the recent assassination by rivals of the rebels’ military chief have kindled doubts about whether the opposition forces could maintain a united front if the oil-rich Mediterranean nation were to come under their control.

The gains in recent days have included rebel advances in the city of Zawiyah — a key strategic city linking the capital to neighboring Tunisia — where they have captured the country’s only functioning oil refinery and the highway to the western border. And early Saturday, news reports said the strategic town of Brega is now completely under rebel control.

Although rebel gains in the past have often been followed by reversals, the recent victories against government forces, on fronts that had been stalled for months, have renewed optimism among the rebels, some of whom now predict the fall of the capital within weeks, possibly days.

Gaddafi, in speeches broadcast on state media, has warned those in the capital that the rebels are criminals and members of al-Qaeda and that their ascent to power in Tripoli would turn Libya into another Iraq. International leaders have expressed concerns over destabilization during a possible post-Gaddafi era.

But rebel leaders insist their takeover would lead to massive street parties heralding democracy — not the start of a destructive civil war.

In preparation, a rebel force largely made up of fighters from the capital has trained for months with special forces from the Persian Gulf emirate of Qatar. The plan is for them to protect strategic locations, infrastructure and ancient sites in Tripoli and surrounding areas, their commanders say.

Another, more elaborate plan by the internationally recognized rebel government is designed to ensure democratic elections overseen by the United Nations within eight months, according to a document provided to several news agencies.

“For months, we have been gathering information in Tripoli and shipping weapons, money and men to the capital,” said Abu Oweis, the founder and deputy commander of the Qatari-trained Tripoli brigade. “We are completely ready to take over,” he added. “All people there will be very happy.”

The brigade’s temporary headquarters, a school building near the city of Zintan on the vast plateau of the Nafusa Mountains, was stocked with ammunition during a visit Thursday. Commanders worked on laptops and used satellite phones as recruits assembled their weapons.

Oweis said his troops would arrest “over a hundred” high-profile Gaddafi loyalists designated as criminals and potential troublemakers by the rebels’ Transitional National Council, which for now is based in the city of Benghazi in eastern Libya.

The rebel leaders succeeded in quickly gaining diplomatic recognition from countries around the world, including the United States. International support, in which Qatar and the United Arab Emirates play a key role, has given the rebels access to frozen assets that once belonged to Gaddafi, as well as weapons deliveries from abroad.

Cargo planes from the United Arab Emirates could be seen in Benghazi’s airport Monday, and rebels have turned a slab of highway in the western mountains into a provisional airstrip where they regularly receive cash and automatic weapons from representatives of the Transitional National Council.

People fleeing the capital have said they feared violence in the coming weeks if Gaddafi’s grip on power weakens. But they said they were less afraid of the rebels than of what Gaddafi loyalists might do when cornered.

“There was no chaos when the other Libyan cities were liberated, so why would there be chaos in Tripoli?” said Ahmad Nafa, an unemployed engineer who came to the mountains with his family to join the uprising.

At the western front’s war room in Zintan, with commanders working radio sets connecting them to units in the field, some cautioned against too much optimism over the plan to establish security in the capital.

“We must be realistic and expect some days of chaos in the capital after Gaddafi falls,” said Abbas Milad, a commander.

The former air force officer predicted a year of instability following what he said would be the “complete victory of the revolution.”

But Tripoli would not become a second Baghdad, Milad insisted.

“We are not foreigners entering a strange land,” he said. “We are Libyans liberating our own country. That makes a huge difference.”