A backstage struggle for control of United Nations programs providing protection to about 8 million refugees worldwide was resolved last week when the African nations agreed not to challenge Secretary General Javier Perez de Cuellar's choice for head of the politically delicate operations.

Perez de Cuellar appeared to have avoided a confrontation on the issue, involving African complaints that the agency did not devote enough effort to Africa's huge refugee problems, by informing delegates that he intended to renominate the incumbent U.N. High Commissioner for Refugees, Poul Hartling of Denmark, for three years rather than the usual five.

Sudan and several other African and Islamic nations had held out for the Sudanese candidate, Minister of Religion Dafalla Haq Yousif Medani. But a Sudanese diplomat said last week he had told Perez de Cuellar, "We are not going to press it." Hartling's appointment was expected to be announced soon.

The contest had become one of personalities, but its origins lay in the United Nation's bloc politics and involved a split within the Third World as well as between North and South.

The refugee agency, created in 1951, had long been viewed as one of the most essential and successful of the U.N. operations. It has a repution for effectiveness, while remaining virtually apolitical, and for a willingness to cut through red tape to serve the genuine needs of people and governments. The agency was the recipient of the 1981 Nobel Peace Prize.

This year, a number of Third World countries, as part of a campaign for increased influence throughout the United Nations, argued that the agency should be headed by someone from a country currently experiencing refugee problems.

They noted that until Hartling, a former Danish prime minister, took office five years ago, the agency had been headed by a Pakistani, Prince Sadruddin Aga Khan.

The countries that serve as reluctant hosts to refugee populations have been pressing the agency to expand beyond basic relief needs and to get involved in the infrastructure of development--the roads, water supplies, medical programs and educational facilities required by vast refugee influxes in remote regions. This approach has been resisted by the West.

In addition, African nations have long been irritated by what they perceive to be the agency's lack of concern for the African continent's refugee population of approximately 5 million--the bulk of the world's refugees -- and overemphasis on the refugee crises in Central America, Pakistan and Indochina, which are of greater political concern to the West.

The agency is funded exclusively by voluntary contributions -- $475 million last year -- much of which comes from the West and is earmarked for particular projects. The donor nations have remained firm in their insistence on control at the top.

The amount earmarked for Africa has declined, despite a special fund-raising conference for the African refugees, from $178 million in 1980 to $160 million in 1981, and to an estimated $158 million this year.

Sudanese representative Omar Birido argued that other agencies dependent on voluntary contributions operate successfully with Third World directors. He said most Western countries have promised to sustain their contribution level, whoever is at the helm of the refugee agency. He suggested that his candidate, Medani, would be better able to tap the wallets of members of the Organization of Petroleum Exporting Countries.

"In any case, we, the host countries, are the real donors to the refugees," Birido said.

Medani, 46, is a former education minister with experience in private business. American officials said that there are no personal objections to Medani and that Sudan has been a model nation in treating its own refugee problems.

Nevertheless, U.N. officials said that the "political reality of funding" is the primary reason that Perez de Cuellar has bowed to the donors' demands.

They acknowledged that Hartling's bid for reappointment, which was backed by the United States as well as Scandinavian nations, looked doubtful earlier this year because of his age, 69, and growing complaints against him. Third World countries have complained that he sought to recruit his top aides only from Western nations and overtly violated U.N. personnel procedures by soliciting job candidates directly from the governments of Australia, Japan and Canada.

Now that the secretary general has announced his intention, the African group must meet to decide whether to continue their challenge to Hartling, which now involves a challenge to Perez de Cuellar.