For nearly 28 years the U.S. government has harbored an increasingly embarrassing secret: A CIA tip to South African intelligence agents led to the arrest that put black nationalist leader Nelson Mandela in prison for most of his adult life.

But now, with Mandela en route to the U.S. to a hero`s welcome, a former U.S. official has revealed that he has known of the CIA role since Mandela was seized by agents of the South African police special branch on Aug. 5, 1962.

The former official, now retired, said that within hours after Mandela`s arrest Paul Eckel, then a senior CIA operative, walked into his office and said approximately these words: ''We have turned Mandela over to the South African security branch. We gave them every detail, what he would be wearing, the time of day, just where he would be. They have picked him up. It is one of our greatest coups.''

With Mandela out of prison, the retired official decided there is no longer a valid reason for secrecy. He called the American role in the affair

''one of the most shameful, utterly horrid'' byproducts of the Cold War struggle between Moscow and Washington for influence in the Third World.

Asked about the tip to South African authorities, CIA spokesman Mark Mansfield said: ''Our policy is not to comment on such allegations.''

Reports that American intelligence tipped off the South African officials who arrested Mandela have circulated for years. Newsweek reported in February that the agency was believed to have been involved.

Mandela, now 71, arrives in the United States June 20 as part of an international tour to bolster the anti-apartheid movement. The deputy African National Congress president, widely regarded as the world`s pre-eminent political prisoner when he finally was released in February, is due to be honored by a ticker-tape Broadway parade and to address a joint session of Congress.

But in 1962 the CIA`s covert branch saw the African National Congress as a threat to the stability of a friendly South African government. At the time, that government not only had just signed a military cooperation agreement with the United States but also served as an important source of uranium.

The CIA knew of Mandela`s whereabouts because it had put an undercover agent into the inner circle of the African National Congress group in Durban, according to Gerard Ludi, a retired South African intelligence official.

Mandela was being sought as a fugitive for his anti-apartheid activities. The morning after a secret dinner party with other congress members in Durban, Mandela, dressed as a chauffeur, ran into a roadblock. He was immediately recognized and arrested.