President Clinton today offered a broad expression of contrition for what he called his country's shameful legacy in Africa, including America's role in the slave trade and its support for repressive anti-communist dictators during the Cold War.

While saying it is "well not to dwell too much on the past," Clinton nonetheless told a crowd in this village outside Kampala, the Ugandan capital, that Americans should recognize and repent for the reality that "the United States has not always done the right thing by Africa."

"Going back to the time before we were even a nation, European Americans received the fruits of the slave trade," Clinton said. "And we were wrong in that."

In the past, Clinton had considered and rejected making an official apology to African Americans for slavery as part of a larger campaign to promote racial reconciliation. Clinton aides said the president believed the idea lacked broad support and was more likely to distract people than encourage healing. Aides repeatedly said Clinton would not issue an apology during his six-nation Africa tour.

But Clinton apparently became so taken by the spirit of the moment -- after listening to a long speech by Ugandan President Yoweri Museveni about Africa's troubled history -- that he launched into what his own aides said were impromptu remarks about the role the United States played in Africa's tragedies.

What followed was not strictly speaking an apology, but a remarkably all-encompassing statement of contrition. Many of Africa's grievances, Clinton said, are not ancient matters.

"In our own time, during the Cold War, when we were so concerned about being in competition with the Soviet Union, very often we dealt with countries in Africa and other parts of the world based more on how they stood in the struggle between the United States and the Soviet Union than how they stood in the struggle for their own people's aspirations to live up to the fullest of their God-given abilities," he said.

The president offered no specifics, but the history he referred to was a well-documented chapter in the Cold War. A prominent example is the nearly 30-year record of U.S. support for the anti-Soviet regime in the former Zaire, where strongman Mobutu Sese Seko flagrantly enriched himself while brutally repressing civil liberties and letting his nation fall into grinding poverty. U.S. support for Mobutu waned after the collapse of communism, and he was toppled last year in a coup and died in exile soon afterward.

Washington likewise supported repressive regimes in Liberia and other nations during the Cold War, and supported anti-communist guerrillas in a three-decade war against the government of Angola.

But Clinton -- addressing a crowd of brightly dressed children from a stage in a pasture behind a Ugandan primary school -- said it is neither slavery nor geopolitics for which Americans most urgently need to redeem themselves.

"Perhaps the worst sin America ever committed about Africa," he said, "was the sin of neglect and ignorance. We have never been as involved with you, in working together for our mutual benefit, for your children or ours, as we should have been."

Ordinarily, Clinton aides tout his empathy and a flair for the politics of symbolism and sentiment. But his spur-of-the-moment ruminations today caused consternation among his traveling delegation. Some advisers said they worried that Clinton's remarks may have been invested with more significance than he intended and could spur unwanted controversy at home.

A bill has been introduced in Congress that would have the government apologize for slavery, following a similar official apology to Japanese Americans for involuntary internment during World War II. But administration officials said that even among many African American leaders there is widespread sentiment that an apology for slavery would be a frivolous gesture.

Civil rights leader Jesse L. Jackson, the administration's special envoy to Africa who is part of the president's official delegation here, applauded his decision to "recognize the historical immorality in the relationship" between the United States and Africa, even as he warned reporters against a "preoccupation with the semantics of an apology."

Susan Rice, the assistant secretary of state for African affairs, was criticized this week by a Ugandan newspaper for saying that there were both "buyers and sellers" in Africa who participated in the slave trade. Rice said today that she stands by that reading of history, but called laying responsibility for slavery a "largely irrelevant" issue.

The sense of surprise at Clinton's statement was compounded by the fact that it was delivered in Uganda rather than his last stop, Senegal. The vast majority of slaves in the New World were West Africans or their descendants, and many left this continent via Senegal's Goree Island, which Clinton is scheduled to visit before heading home.

Clinton's and Museveni's remarks in some ways offered a striking contrast. While Clinton noted that Africa often has been victimized by outsiders, the Ugandan president emphasized home-grown lapses, including governments that quashed free markets and killed their own people.

"Africa cannot be marginalized by the world," Museveni said. "It is only the leaders of Africa who can marginalize Africa by their own actions."

Before Museveni took power in 1986, Uganda's government was a leading example of self-inflicted suffering. The military dictatorship Idi Amin led from 1971 to 1979 killed between 100,000 and 500,000 people, according to various estimates. Milton Obote -- who ruled Uganda both before and after Amin -- also was blamed for the deaths of hundreds of thousands.

Although Museveni first took power by force and his government has yet to allow political parties to compete in elections, the Clinton administration has applauded Uganda for broadening civil liberties and reforming its economy.

Museveni is implementing a program of universal primary education, doubling the school population to 5.3 million pupils. The U.S. government already gives Uganda about $10 million for primary schooling and literacy programs, and Clinton today pledged an additional $120 million over two years to train more teachers and connect schools to the Internet. Clinton announced the grants at the school here, where children learn in classrooms with dirt floors. He and first lady Hillary Rodham Clinton were treated to an exuberant song-and-dance ceremony by the children. The president at one point joined in, clapping and swaying, ever so modestly, in rhythm with the drums. CAPTION: President Clinton listens with primary school children in Kisowera, Uganda.