KAMPALA, Uganda (AP) _ Government troops retreating before a fierce rebel attack near Kampala poured into the streets of the capital Wednesday robbing and harassing civilians who fled by the hundreds, witnesses said.

Gunfire was heard all day, and by the afternoon stores and offices in downtown Kampala wereclosed and only unruly soldiers roamed the streets. At times, the shooting was believed to be connected to rampages rather than a result of clashes between the army and the rebel National Resistance Army guerrillas.

Witnesses said soldiers robbed and harassed pedestrians in downtown Kampala and prevented residents from returning to their homes in the southwestern suburbs.

A member of the ruling military council, Lt. Col. Eric Oduor, issued an appeal for calm over state-run Radio Uganda and ordered all soldiers to return to their barracks.

Skirmishes have occured on the outskirts of Kampala and began to escalate over the past week despite a peace accord signed Dec. 17 to end a five-year conflict.

A source on the military council, who requested anonymity, said Wednesday's unauthorized influx of soldiers into Kampala came after commanders decided to withdraw artillery units from a position 15 miles to the southwest where army troops had been confronted by the guerrillas.

Officials in neighboring Kenya, which helped the government of Uganda and rebel guerrillas negotiate the accord, called for an emergency meeting in Nairobi on Friday.

Kenya's Foreign Minister Elijah Mwangale said that President Daniel arap Moi had invited Gen. Tito Okello, Uganda's head of state, Tanzania's President Ali Hassan Mwinyi and National Resistance Army leader Yoweri Museveni to the talks.

Mwangale, commenting on the situation Wednesday, said: ''It is still explosive ... Really, we just have to wait and see what happens.''

Moi chaired the negotiations which began in August and resulted in the peace accord, and Tanzania has offered to provide observers to monitor a cease-fire called for in the peace accord.

Okello was quoted by the state radio Wednesday as saying he would be willing to meet with Museveni in Nairobi to discuss the troubled peace process. The two have not met since the signing of the accord last month.

In addition to an immediate truce, the accord called for an eventual demilitarization of the government army, the National Resistance Army and four other rebel groups that had fought the civilian government of Milton Obote, before it was overthrown in a coup last July.

Few of the provisions have been adhered to, and fighting with artillery, rockets and helicopters gunships continued. Government troops and NRA rebels last Friday fought their fiercest battles since the signing of the accord.