After nearly four months of fighting in Uganda and negotiating in Kenya, Uganda's military government today signed a peace agreement here that gives the rebel National Resistance Army equal power in running the country.

The agreement calls for an immediate cease-fire and disarming of combatants in the bloody civil war that broke out after a July coup toppled the government of president Milton Obote. It also calls for a conference to set up general elections and return to civilian rule and creation of a new Army made up of both rebel and government troops. International observers are to be invited to Uganda to monitor the truce.

In the fighting, which precipitated the near collapse of Uganda's economy and plunged much of the nation into anarchy, the rebels had soundly defeated ill-disciplined government troops in a number of battles and had taken control of a third of the East African country.

Today's agreement is testament to the military strength of the 10,000-man National Resistance Army. Its leader, Yoweri Museveni, was named vice chairman of the new ruling Military Council. The rebel army was given the same number of members on the ruling council as the existing government and the rebels were guaranteed equal power in commanding the country's armed forces.

Kenyan President Daniel arap Moi, who chaired the long peace negotiations, hailed the agreement in a formal signing ceremony this morning as the "dawning of a new era of peace in Uganda." He said it offered the country a chance of "transcending the trappings of tribalism, regionalism and religious differences" that have spawned "wanton" violence in the country for decades.

During the eight-year rule of Idi Amin, human rights groups estimated that 300,000 Ugandans were killed by military forces. During the recent four-year rule of Obote, Amin's successor, nearly 250,000 civilians are estimated to have been killed or to be missing. In the past 15 years, the infrastructure of Uganda has crumbled as foreign investors have abandoned what was one of the more developed countries in East Africa.

Gen. Tito Okello, the head of Uganda's military government, also spoke optimistically during today's signing ceremony. He said he was confident that the accord would bring Uganda "stability, prosperity, national unity and democracy."

Museveni, however, was not so sanguine. The rebel leader, who led a guerrilla war for nearly four years against Obote's government before taking on Okello's forces, vowed to abide by the provision of the 50-page peace agreement. But his belligerent remarks at the signing ceremony suggested that he had doubts about how long the agreement would last.

"My interest is not in the vice chairmanship," said Museveni of the office he is given by the agreement. "My interests are the interests of the population, and if those are not guaranteed by any agreement, then we shall not be a party to that agreement . . . .

"If you are really serious, and I hope [Okello] is serious and is an honest man, definitely there will be peace in Uganda . . . . If you want peace, we are serious partners. If you want trouble, we are also serious opponents."

Museveni further said that the agreement "will have no purpose" until government soldiers who have committed atrocities against civilians are punished.

"Amin killed our people from 1971 to 1979. Milton Obote killed our people from 1981 to 1985. And the Military Council has been killing people even recently . . . . The violation of human rights that has gone on in Uganda is simply beyond belief. We are not going to rest until those who are responsible for certain massive hemorrhages of the lives of our people are brought to book."

Rebel leaders specifically have accused the current head of Uganda's armed forces, Lt. Gen. Basilio Olara Okello, of responsibility for atrocities committed since the July coup. A provision of the today's peace agreement says that all members of the security forces who have violated human rights "shall be immediately punished." It was unclear if Museveni and the rebel force would try to apply that provision to the chief of the armed forces.

Disagreement on the provision concerning punishment of human rights violators, according to a Kenyan government spokesman, delayed the signing of the peace agreement for five days. Each morning since Friday, a red carpet has been rolled out at the Kenyatta Conference Center here in anticipation of the signing ceremony.

The peace agreement specifically bars from participation in the new government any person who served under Amin in the "notorious State Research Bureau and Public Safety Unit." It presided over the torture of civilians, according to human rights groups. The agreement also called for the punishment of all those who committed atrocities during Amin's reign.

Several military officers who served in Amin's government returned to Uganda after the July coup and joined forces with the current military government. It was unclear how the agreement's provision would apply to them.

Rebel forces in Uganda greeted the peace agreement today by releasing 39 hostages who were aboard a Uganda Airlines plane hijacked Nov. 10. The hostages were flown from Kasese in western Uganda to Entebbe airport, near the capital of Kampala.

Reports from Kampala, where the signing ceremony was broadcast live on radio, said the peace announcement created little enthusiasm.

Under the peace agreement, all armed troops are supposed to pull out immediately from Kampala, a city that has been decimated in the past four months by fighting, looting and random murder.