After two days of artillery bombardment and heavy street fighting, rebels of the National Resistance Army have taken effective control of the Ugandan capital of Kampala, according to reports from western diplomats in the city.

Reports from Kampala said tonight that several thousand government soldiers had fled the capital during the day, some of them killing civilians and looting as they went. They were believed to be heading toward Jinja, a city 50 miles to the east, where other government soldiers have gathered. Gen. Tito Okello, the head of Uganda's military government, was reported by news agencies to be in Jinja.

By nightfall, gunfire in Kampala reportedly had subsided as isolated groups of government soldiers were still defending the Parliament building and Nile Mansion, the government's executive headquarters.

Telephone and telex lines with Uganda have been cut. Radio Uganda is off the air, and the country's main airport has been closed. Reports on today's fighting have come by radio from western diplomats in embassies in Kampala.

The State Department reported in Washington that there are about 170 Americans in Uganda. About 100, including 21 U.S. Embassy personnel, are in Kampala, and all are safe and accounted for.

The apparent fall of Kampala comes less than five weeks after Yoweri Museveni, leader of the National Resistance Army, signed a peace agreement in which he was given equal status with the military government in running Uganda. The government had been forced into signing that agreement. Its ill-disciplined troops had been routed repeatedly by Museveni's 10,000-man army, which during the past six months had seized control of the southwestern third of the country.

Museveni, 45, who calls himself an "intellectual" forced by Uganda's culture of violence into becoming a soldier, never made any attempt to implement the peace agreement he signed in Nairobi last month. He claimed that it was unworkable because government soldiers continued to commit atrocities against Ugandan civilians.

Museveni, who served briefly as defense minister in a civilian Ugandan government in 1979, was openly skeptical of the peace agreement on the day he signed it.

"My interest is not in the vice chairmanship," Museveni said at the Dec. 17 signing ceremony, referring to the position he was to take within a new ruling Military Council. "My interests are the interests of the general population, and if those are not guaranteed by any agreement, then we shall not be a party to that agreement."

Western diplomats in Kampala said recently that Museveni apparently believes he has the military muscle to run Uganda himself.

In recent weeks, diplomats and clergymen have confirmed an increase in looting and raping by government soldiers since the peace agreement was signed.

A spokesman for the rebels said today in an interview with the British Broadcasting Corp. that the National Resistance Army bombarded Kampala as "a last resort" to stop "so many atrocities."

"We said, 'If you can't comply with what we think is right, now we will just resort to bombarding you,' " said Sam Kisseka, coordinator of the rebels' external mission in London.

The heavy fighting in Kampala, much of which was reported to have occurred on streets surrounding the British and the U.S. embassies in the center of the city, is the latest round in nearly two decades of violence in the East African country.

During that time, as many as half a million Ugandans have been killed, most of them by soldiers in the armies of former presidents Idi Amin and Milton Obote. The violence has wrecked the infrastructure of what had been one of black Africa's most developed countries.

Much of the violence has grown out of tribal animosity between the north and south of the country. Museveni's rebels represent a coalition of southern tribes, and the current military government is controlled by northerners, as it has been for most of the past 15 years.

The government came into power last August in a coup against Obote. Museveni's rebels, who had been fighting a guerrilla war against Obote for four years, never accepted the new government and quickly stepped up fighting in the southwest.

Military analysts and diplomats interviewed in Kampala have said in recent weeks that Museveni's rebels would have little trouble taking Kampala. But they added that his army would have a far more difficult time rounding up the heavily armed soldiers who are expected to flee to their home areas in the north.

Former members of Idi Amin's army, who in the past six months had aligned themselves with the military government in Kampala, are expected to take refuge in the northwestern district of West Nile. Members of the Acholi tribe, who make up the core of the government's army, are expected to retreat to the Acholi district in the north-central part of the country.

Analysts predict that Museveni will have the same difficulties controlling northern-based soldiers as the northern-controlled government has had in controlling his guerrillas. There are about 100,000 armed men in the country of 14.5 million people.

In his BBC interview today, rebel spokesman Kisseka said the National Resistance Army had "enough machinery" to control soldiers in the north.

"A decree will be passed. Those who hold the gun, they will have to submit it," Kisseka said. "If they don't, then we will have to disarm them." Kisseka pledged that the rebels would prosecute the number two general in the military government, the chief of defense forces, Lt. Gen. Basilio Olara Okello. He said that Okello, an Acholi, personally "shot 20 people" in Kampala in 1981.

Kisseka promised, however, that the rebels would not punish soldiers or civilians simply because they belong to northern tribes such as the Acholi.

In eastern Uganda near the Kenyan border, at the town of Moroto, there were reports of soldiers looting U.N. famine relief food warehouses.