Egypt has decided to pull out an air defense brigade that it sent to the Sudanese capital of Khartoum last March following an attack on the city by a lone Libyan bomber, according to Pentagon and State Department sources.

The remnants of the brigade, which came armed with light, shoulder-held SA7 missiles, were scheduled to leave by the end of this month following the failure of Egypt and Sudan to set up a new permanent air defense system for the capital based on old Soviet SA2 and SA3 missiles, according to these sources.

The withdrawal of the brigade, apparently for military reasons, comes amid increasing division within the Egyptian government over its policy toward Sudan and how closely Cairo should continue to associate with the embattled Sudanese President Jaafar Nimeri.

Interviews with Egyptian officials in Cairo in early January made clear that the issue is regarded as extremely delicate because of Nimeri's unpredictable behavior and the possibility that he might turn on the Egyptians if they press him too hard and even make a new alliance with his chief enemy, Muammar Qaddafi of Libya.

[Close senior aides of Qaddafi and Nimeri met secretly in Paris two weeks ago to discuss ending support for each other's opposition rebels, Agence France-Presse reported Sunday, quoting the London newspaper The Observer.]

Still, Egyptian backing is probably crucial to his fate, for without it his survival in face of the mounting internal opposition to his rule appears uncertain.

Egypt is bound by a defense treaty to defend Sudan against any external aggression. In 1982 the two nations signed an economic integration pact.

The defense treaty does not commit Cairo to helping Nimeri against internal unrest but Egyptian military intervention already has saved him from his enemies at least twice -- once in 1971 against the Communists and a second time in July 1976 against a Libyan-backed armed insurrection in the capital.

One well-informed Sudanese government source said that he was convinced that the Sudanese Army no longer fully supports Nimeri. "But they want a guarantee the Egyptians will not intervene if they act," he remarked.

Apparently no such guarantee has been forthcoming, largely because Egyptian and U.S. officials are worried about chaos erupting if Nimeri suddenly exits from the stormy Sudanese political stage.

They admit, however, that relations between Egypt and Sudan have become "delicate" these days and that Sudan has become a top foreign policy preoccupation.

The fear here is that Soviet-backed Libya and Ethiopia, already deeply involved in aiding an armed rebellion against Nimeri's government, will both rush to help whoever tries to take his place in a crisis.

One sign of the shifting Egyptian attitude is the increased number of contacts between Cairo and Sudanese opposition representatives since last spring. These Sudanese emissaries have been traveling to Cairo with the message that Egypt is making a grave error in associating itself so closely with the Nimeri government.

"They have been emphasizing the need for Egypt to stop supporting Nimeri to maintain good relations with the Sudan. Otherwise, whatever regime comes will hold Egypt responsible," said the Sudanese source, who has good contacts with both the Egyptian government and his country's opposition.

Egyptian policy-makers are aware of their predicament but do not know what to do. Underlying their uncertainty is an unspoken fear that Nimeri is unpredictable enough, if they push too hard, to seize upon the growing anti-Egyptian sentiment in his country to throw out the Egyptians in a bid to bolster his fading popularity.

Egyptian President Hosni Mubarak has been using a kid gloves approach toward Nimeri, preaching moderation and reconciliation to him in their frequent meetings. But Nimeri's decision in January to hang the 76-year-old leader of the Republican Brothers, a moderate Moslem sect, illustrates that the Mubarak soft line is not working.

Egypt also has been trying to act as mediator between Nimeri and the leader of the armed rebellion in southern Sudan, John Garang. But in early January, Garang ruled out talks and vowed to continue fighting until Nimeri is overthrown.

The Egyptian political establishment is divided about Nimeri, but both agree on the centrality of the Nile River in Egypt's calculations toward him and Sudan in general.

The drought in Ethiopia, which has affected drastically the amount of water flowing to Egypt, and the Ethiopian-backed rebellion in southern Sudan have sharpened the Egyptian focus on the Nile.

The rebels have forced a halt to work on the Jonglei canal project that promised to provide additional tens of billions of cubic meters of water annually, most of it for Egypt.

A pro-Nimeri faction, led by Defense Minister Mohammed Abu Ghazala, is arguing that the stategic importance of Sudan on the upper waters of the Nile, combined with the threat from Ethiopia and Libya, make it imperative that Cairo stick with Nimeri no matter what.

Abu Ghazala, in his outlook, is close to the Reagan administration in viewing Sudan in terms of the communist "threat" to Africa in general and Egypt in particular and sensitive to the fact that Ethiopia and Libya are both Soviet armed.

An opposing faction, led by civilians in the office of the presidency and the Foreign Ministry and reportedly supported by some top Egyptian intelligence officers has been trying to draw a distinction between Egypt's support of Sudan as a country and Nimeri as a leader.

This faction also has been pointing to the need for Egypt to view Sudan as part of an overall "Nile basin policy" that takes account of the equal importance of Ethiopia and Uganda where the headwaters of the Nile are located.

This school of thought believes Egypt must improve its relations with Ethiopia in particular and work to dissociate Cairo from the Nimeri regime before it is too late.

This "civilian faction," as one Arab diplomat called it, includes some of President Mubarak's closest aides, including Osama Baz, his top foreign affairs adviser. Many top Foreign Ministry officials agree privately.

Asked in an interview whether he thought Egypt should continue to back Nimeri, Butros Ghali, the minister of state for foreign affairs in charge particulary of Egypt's relations with Africa, replied, "I cannot answer on the diplomatic level, but I admit it is a valid question and a very important problem for this country."

Ghali and Baz have been leading the Egyptian campaign to improve Egypt's relations with Ethiopia and to act as mediator between Nimeri and rebel leader Garang.

There is still a general feeling here, albeit a fading one, that Nimeri's problems could be solved politically, even at this late date, if he would make some conciliatory gestures toward southern Sudan.

These, Egyptian policy-makers say, would involve restoring regional autonomy there, backing off on his quest for a strict application of Islamic law to the Christian-led south and giving the south a share in Sudan's new-found oil wealth located there.

At the heart of the Egyptian dilemma is the lack of any attractive alternatives to Nimeri as a leader.

Egyptian fears for the future of Sudan are only made worse by Garang's Ethiopian and Libyan connections and the previous strong opposition to Egypt of Sadiq Mahdi, who is the leader of Sudan's powerful Mahdist movement and a leading opposition figure.

Mahdi has been among those sending emissaries to Cairo to reassure Egyptian leaders that he is not anti-Egyptian.

Before the 1976 abortive coup attempt that Mahdi led, he had close ties with Libya's Qaddafi, now a sworn enemy of the Mubarak government.

The other possible course for the Egyptians, who still have a lot of influence with the Sudanese military, would be to back an officer or a group of officers in the Sudanese Army in a takeover bid.

Egyptians officials seem to feel this is easier said than done, however. They point out that the Army is so weak and internally split among factions with differing political allegiances that finding anyone capable of holding it together other than Nimeri is a risky business.

In addition, the Army is increasingly preoccupied with containing the southern-based rebellion, making any concerted action against Nimeri extremely difficult.

This lack of alternatives to Nimeri, as the Egyptians see the situation there, has led to a kind of "hope for the best" policy of sticking with him for the time being -- or at least until the badly divided opposition forms some kind of united front and viable alternative for Egypt to support.