The leaders of two of Africa's most bitter antagonists, Sudan and Uganda, signed a surprise peace deal today, agreeing to restore diplomatic ties and vowing to stop supporting rebel groups trying to topple the government of the other.

The agreement was brokered here by former president Jimmy Carter, who looked on benevolently as Ugandan President Yoweri Museveni shook hands with Lt. Gen. Omar Hassan Bashir, the president of Sudan.

Carter called the deal "a wonderful step toward peace and reconciliation."

Under the 11-point agreement, the rivals pledged to restore diplomatic relations that were broken off five years ago, with each country accusing the other of aiding armed rebels operating along their 250-mile border. Now, each is to post diplomats in the other's capital within a month and reopen a full embassy by the end of February. They are also obliged to disarm and disband terrorist groups operating on their soil.

Sudan has been a base of operations for the Lord's Resistance Army, a group that has abducted as many as 20,000 children in northern Uganda and forced them to fight, often after being drugged or sexually abused. Sudan has also been accused of providing materiel support to a second Ugandan rebel group, the shadowy Allied Democratic Forces, which operates from the mountains on Uganda's western frontier with Congo.

Uganda in turn has provided bases and materiel support for the Sudanese People's Liberation Army, which has been fighting a 16-year civil war against the Khartoum government for more autonomy for southern Sudan. When Congress voted to spend millions of dollars on tents, radios and other "nonlethal" aid for the group earlier in the decade, Uganda was one of the neighboring countries it funneled money through.

The Sudanese and Ugandan governments were on horrible terms, with officials in each routinely accusing the opposite capital of plotting its downfall.

But an official of the Carter Center in Atlanta said the former president was invited by Museveni and Bashir to mediate the conflict last spring and that officials twice traveled to the region to hammer out the agreement.

"One of our goals was to keep this as quiet as possible, simply because having too much attention to something doesn't help," said Joyce Neu, senior associate director of the Carter Center conflict resolution program, who headed the effort.

Neu acknowledged that distrust between the governments "is not all gone, and one of the tests of this agreement will be the implementation." Officials will meet Thursday to discuss specifics on disarming and disbanding the terrorist groups, she said.

Although the Carter Center negotiations remained secret, Sudan and Uganda had appeared intent on making peace on other fronts.

Museveni, who has come under criticism at home and from foreign donors for his defense expenditures, has made Uganda an enthusiastic proponent of the accord that has brought a wobbly cease-fire in the Democratic Republic of Congo, where Ugandan troops have aided rebels. And on Tuesday, Uganda's parliament, with Museveni's endorsement, offered amnesty to all rebels who have been fighting against the government.

Sudan, meanwhile, has made overtures to internal critics and neighboring countries arrayed against its fundamentalist Islamic regime. It has endorsed peace initiatives aimed at ending the civil war, which costs $1 million a day and has claimed an estimated 2 million lives. And earlier this week, the government cited its policy of detente in releasing two Catholic priests and more than a dozen other men accused of plotting bombings in Khartoum, the capital.

CAPTION: President Omar Hassan Bashir of Sudan, left, and Ugandan President Yoweri Museveni shake hands on a deal brokered by former U.S. president Jimmy Carter to restore diplomatic relations.