After 23 years in office, Africa's senior statesman and one of the Third World's most eloquent spokesmen is planning to step down.

Tanzanian President Julius Nyerere, 63, says he will retire from office next year, becoming one of the few rulers in the short history of independent black Africa to relinquish his post voluntarily.

He does not intend to depart quietly. Last month Nyerere accepted the chairmanship of the Organization of African Unity with a blistering attack on U.S. policy toward white-ruled South Africa, and he later urged African nations to withhold payments on their debts to force western governments and financial institutions to negotiate reforms in the international economic order.

The statements were vintage Nyerere, a leader who has forged a reputation as Africa's most vocal critic of the economic inequality between the First World and the Third. He is also a man of irrepressible intellect and consummate charm who manages to impress even those western diplomats who find his foreign policies unpalatable and his socialist domestic policies unworkable.

"He is a humane, decent person with an extraordinary mind and considerable charm," said a senior western diplomat here, "but he clings to notions that are wrong."

Nyerere first announced his retirement plans early this year in a meeting of the executive committee of his Revolutionary Party. Despite pleas from loyalists to stay on, he has reiterated his intention several times since, most recently in an interview last month with the Egyptian weekly El Mussawar. He said that despite "a lot of pressure," he believed he had done "all that I can do to help my country." He said Tanzania needed new leadership to deal with its "new problems." A top Nyerere aide added in an interview that the president believes a peaceful transition of leadership would be an important achievement of political maturity that he would regard as a significant accomplishment.

If he retires as scheduled, Nyerere will leave behind a tangled and uncertain legacy. Nyerere's Tanzania has been both Africa's leader in the struggle for social equity and one of its most conspicuous economic failures. Nyerere has been sub-Saharan Africa's leading socialist visionary and a chief executive who has presided over his own country's slow but steady financial collapse.

Statistics illustrate both his triumph and shortcomings. Tanzania boasts black Africa's highest adult literacy rate -- 70 percent -- thanks to his unswerving commitment to public education. Average life expectancy has increased by 10 years during the last generation through improvements in health care and clean water supplies. At the same time, however, per capita food production has declined 12 percent in the last decade; food imports are rising while exports have fallen steadily and Tanzania is $2.6 billion in debt.

Nyerere claims to revere grass-roots democracy, yet he imposed a centralized economic system and a stifling bureaucracy on a nation of 20 million peasants who appear to have little use for either. He is famous for the learned treatises he has written on underdevelopment and for periodic bursts of self-criticism. Yet knowledgeable Tanzanians say he generally has surrounded himself with aides who echo his own thoughts.

While a scrupulous defender of the rights of refugees, last year he engineered a swap of political fugitives with neighboring Kenya that U.N. refugee officials have termed a violation of international law.

Above all, there is a strong streak of paternalism in the mwalimu -- Swahili for teacher, the honorific Nyerere chose for himself when he became president.

When peasants balked at moving to collectivized villages in the early 1970s, they were forced to relocate, and the result was agricultural disaster. When they refused to grow crops for the legal marketplace because prices were too low, laws were passed forcing each village to produce a certain amount, but he laws proved unenforceable. Nyerere has conceded that his policies raised peasant expectations beyond the government's ability to fulfill them.

There are other, less ambiguous achievements, however. By stressing national institutions and a nationwide public school system, by eschewing favoritism in dealing with Tanzania's 100-plus tribes, and by imposing Swahili as a national language, Nyerere has helped construct one of Africa's rarest entities: a true nation.

By stressing socialist equality, he has given his country a sense of mission, and by invading neighboring Uganda and overthrowing dictator Idi Amin in 1979, he has given Tanzania an epochal moment of moral triumph that may be enshrined in African history as the defeat of Hitler is cherished in Europe.

"For all its problems, this is a remarkably stable country, with dignified, intelligent people, a high degree of religious and ethnic tolerance and many of the attributes of nationhood," said a western diplomat here.

Nyerere has blamed most of Tanzania's economic woes on outside forces beyond his control. Alternate years of droughts and crippling floods, the 1977 collapse of the East African Community, forcing the country into expensive capital investments for railways and power lines, and the $500 million price tag for the war against Amin are all cited as major contributors to Tanzania's plight.

Most of all, Nyerere sees inequities in a world trade system in which the exportable commodities of poor nations such as Tanzania have steadily lost value during the past decade while oil, and vital imports from the industrial West, have increased sharply.

In 1972, Tanzania spent 5 percent of its foreign exchange earnings on imported oil. Last year it spent nearly 60 percent, even though it has cut oil consumption by nearly one-third.

"It is as if we had been robbed," Nyerere has said. "To buy a seven-ton truck in 1981, we had to produce and sell abroad about four times as much cotton, or three times as much cashew, or three times as much coffee, or 10 times as much tobacco as we had to produce and sell in 1976."

He has also said, "It is true internationally that the rich are rich because the poor are poor. The inevitable oversimplification of that statement does not invalidate it."

Nyerere's supporters dismiss the idea that his socialist policies have contributed to Tanzania's problems, pointing out that capitalist countries such as Kenya and the Ivory Coast also are suffering from extreme economic shocks.

"Other countries don't have our policies and they are suffering too," said a top presidential aide.

In a recent interview with South, a London-based monthly magazine, Nyerere conceded he had made "two major mistakes" in the 1970s: abolishing local governments and disbanding local agricultural cooperative unions in favor of large, state-controlled corporations.

"We were impatient and ignorant," he said. "We had these two useful instruments of participation and we got rid of them. . . . The real price we paid was in the acquisition of a top-heavy bureaucracy. We ended up with a huge machine that we cannot operate efficiently."

Nonetheless, many analysts contend that Nyerere is not prepared to dismantle most of the socialist apparatus he personally constructed in Tanzania. They predict that there may be a showdown soon between him and his supporters and a younger generation of pragmatists who are seeking drastic cutbacks to halt the country's decline.

"The president has always tried to maintain a coalition of pragmatists and dreamers," said the Nyerere aide. "He's always tried to combine the two, but he is still very committed to his dream. It's probably true that the balance has shifted for the moment toward the pragmatists, but only a bit."

The aide said Nyerere is determined to honor his promise to retire when his present five-year term expires next year, although he is expected to retain his position as chairman of Tanzania's sole legal political party, the Revolutionary Party, until 1987. But others predict that there will be intense pressure on him to remain, especially from top bureaucrats who fear that their influence and their jobs may be at risk once he leaves.

Nyerere's relations with the United States, which improved dramatically during the Carter administration, have deteriorated under President Reagan. Nyerere has been harshly critical of U.S. support for South Africa and has accused the Reagan administration of encouraging South African aggression against its black-ruled neighbors.

Some of his top aides say that they believe that the United States is encouraging the International Monetary Fund to coerce Tanzania into politically risky austerity measures and that the Americans are quietly gloating over the failure of Nyerere's socialist experiment.

American diplomats have insisted that such views are mistaken, but the United States has halted further foreign aid expenditures in Tanzania because the Tanzanians have been tardy in paying an $8 million debt.

Last April Nyerere's heir apparent, prime minister Edward Sokoine, was killed in an automobile accident. In many African states, the loss of such a national figure might create an unfillable void. But there were several credible candidates to succeed Sokoine.

The man Nyerere chose, former foreign minister Salim Ahmed Salim, a veteran diplomat of international stature, is now attempting to build a base of political support inside Tanzania. He has trod a careful path so far, refusing to commit himself publicly or privately, according to close aides, on the country's future economic direction for fear of alienating popular support or -- perhaps more important -- Nyerere himself.

"Julius has been in charge for too long, but people love him and they don't want to embarrass him," said a senior diplomat. "Salim's trick will be to allow Nyerere to maintain his image as the George Washington of Tanzania while gently rotating the economy from under him."