The new Morocco-Libya alliance could benefit much of North Africa - if it holds. The surprise federation attempts to end almost a quarter century of tension between the two nations.
King Hassan II's overture to Libya was based largely on his desire to end Libyan leader Muammar Qaddafi's financial and armed support for Polisario rebels fighting Morocco for control of the Western Sahara.
But if he is successful in developing the federation, this could also:
* Help to induce Colonel Qaddafi to moderate his policies by bringing him back into the Arab political framework.
* Restore unity to the Islamic Conference, in which King Hassan is a prime mover.
* Help Morocco's strained economy by exploiting Libya's seemingly insatiable appetite for foreign workers.
* Begin to patch up divisions within the Organization of African Unity. The war over the status of the Western Sahara has been one of the major sources of conflict within the pan-African organization.
For Libya, the federation could help repair relations with neighbors. Qaddafi has begun to feel the strain of isolation in the Arab world at a time when his bitter enemy, Egypt, is being welcomed back. And with Libya's economy in serious trouble, Qaddafi is having to cut back on his adventures in spreading a new brand of revolutionary Islamic thought. His efforts in this area stretch from Chad to the Philippines.
The King revealed in a radio broadcast that his decision to offer a form of union with Libya last month was made on the spur of the moment.
''I was personally surprised by myself while talking,'' he said. He added that his proposal was received by Qaddafi ''with amazement.'' Such calculated opportunism exemplifies Hassan's confidence in his diplomacy.
Morocco's major Arab allies - Egypt, Sudan, Saudi Arabia, and Tunisia - were startled by Hassan's thunderbolt, but they have reacted with more calm than have Washington and Paris because of their confidence in King Hassan's role as the Metternich of the Afro-Arab world.
When the Reagan administration heard about Hassan's alliance with the US's principal targeted enemy in Africa, it sent Gen. Vernon Walters - King Hassan's old adviser and friend - hurrying to the Moroccan capital of Rabat to discover what was behind the move. It also caused French President Francois Mitterrand to zoom off to Rabat on two visits last weekend.
But there can be no certainty that the federation will last. In his 15 years in power, Qaddafi has signed six abortive union agreements - two each with Egypt and Sudan, one with Tunisia, and one with Syria.
Hassan began a series of discussions with Qaddafi in July after the Libyan leader's tentative approaches for ending a period of conflict that began in about 1960. At one stage Qaddafi mounted a radio campaign urging the Moroccan Army to overthrow the King. Hassan responded with a radio counterblast that took the form of a single program beamed to Libya for 24 hours nonstop consisting of the sounds of yapping dogs.
The bottom line of King Hassan's condition for nurturing the alliance is ending Qaddafi's connection with the Polisario rebels, who have mounted a nine-year struggle for control of the Western Sahara, which Morocco occupied in 1975 after Spain withdrew. Hassan is campaigning for international acceptance for incorporation of the territory into the kingdom of Morocco.
The King has staked his throne and committed vast treasures of Moroccan wealth and lives to this cause. About 200,000 Moroccan troops are engaged in the fight with Polisario, even though the struggle has been made easier for the Moroccans since a continuous wall was built across the desert frontier between the Western Sahara and Morocco two years ago.
This extends across almost the full width of the territory, and consists of sandbanks two to three yards high, flanked by mine fields and barbed wire. It is fortified with observation posts, artillery emplacements, underground quarters for troops, electronic sensors, and radar installations. The whole defense area covers about 17,000 square miles. But it still leaves the Polisario considerable freedom of movement across the rest of the sandy terrain, which is about the size of the US state of Colorado.
The wall, built from 1980 to 1982, stretches in a southwesterly arc from from the old Spanish Sahara-Morocco frontier to Smara and Bou-Craa, and ends at the Atlantic Ocean coastal settlement of Boujdour. It encloses all the most productive parts of the Western Sahara, including the formerly rich Spanish phosphate mines at Bou-Craa.
The completion of this desert wall - once known as ''Hassan's folly'' - changed the nature of the fighting in the prolonged desert war by robbing the Polisario of its earlier military initiative - though the movement has tenaciously continued to fight a war of attrition.
The Polisario's two main allies in the past have been Libya and Algeria, which helped to sustain it with arms and economic support. The loss of Libya's support is therefore a major setback for the King's Saharan enemies.
Algeria has recently shown some willingness to see a negotiated settlement of the struggle, but it still insists on the Saharans' right of self-determination through an internationally supervised referendum.
One other diplomatic obstacle stands in Morocco's way: the recognition by 54 nations (half of them African) of the Sahara Arab Democratic Republic, the state declared by the Polisario. However, the Organization of African Unity has agreed that the continent's leaders will abide by the results of a properly conducted referendum.
If the Morocco-Libya alliance were to hold up for at least a year, it could facilitate Morocco's efforts to conduct a referendum that will satisfy its own interests as well as meet the conditions of Algeria and the rest of the OAU.
Apart from the West Sahara question, the other major implication of King Hassan's initiative is the effect it will have on the war in Chad. It was this concern that sent the French President scurrying to Rabat.
France is militarily committed to supporting the Chad regime of Hissein Habre against his challenger, Goukhouni Woddei, who is backed by the Libyans. The French want to ensure that there will be no trade-off of Moroccan support for the Libyan-supported Chad rebels in exchange for Libyan support in the Sahara. Mitterrand also sought to discover the possible implications for France's military role in Chad of the mutual defense clause in the Moroccan-Libyan treaty.
The French naturally hope that Hassan's influence will prevail over Qaddafi in persuading him to withdraw his forces from Chad as a quid pro quo for the French withdrawal. If this arrangement could be reached it is possible that two of Africa's crisis areas would be defused by the Hassan-Qaddafi treaty.
From the Arab vantage point, the biggest potential gain would be if Qaddafi could be harnessed back into the Arab League: This would involve ending his open hostility to Egypt, Sudan, and Saudi Arabia, as well as ceasing (or at least easing off) his support for Iran in its war against Iraq.
King Hassan's imaginative act of diplomatic opportunism could open the way for a number of far-reaching changes in Africa and the Middle East.
But - and it is a big but - it is an open question whether the maverick and mercurial Colonel Qaddafi be relied upon to remain in a constructive alliance with the conservative, single-minded royalist Moroccan leader. Hassan is committed to the cause of moderation in the Arab world and his natural foreign-policy sympathies, unlike Qaddafi's, are with the Western community.