French officials are attempting to end a diplomatic embarrassment for President Francois Mitterrand that has arisen out of last month's surprise announcement of a political merger between Libya and Morocco.

The somewhat unlikely marriage between two very different Arab states -- one radical, the other conservative -- came as a shock to France, which has taken care to cultivate its political and historic ties with North Africa. Morocco's King Hassan II has long been regarded here as a staunch ally -- the political reverse of Libya's Col. Muammar Qaddafi.

While attention in the United States has focused on Qaddafi's apparent diplomatic success in winning over the king, French concern has centered on the implications of the move for the balance of power between Morocco and Algeria, which are vying for control over the Moroccan-ruled territory of Western Sahara.

It is widely believed here that King Hassan's primary purpose in seeking an alliance with Libya was to strengthen his hand in his 10-year guerrilla war in Western Sahara with the Algerian-backed Polisario Front. The treaty presumably means that Libya, which supported the Polisario until last year, will now pool its resources with Morocco.

Algerian suspicions were fueled by an unannounced visit to Morocco that Mitterrand made last week in an apparent attempt to find out more about the treaty directly from Hassan. Unfortunately, the previously planned visit happened to coincide with a referendum in Morocco to ratify the treaty.

The Algerians were not reassured by the fact that Mitterrand went to some lengths to be out of Morocco on the day of the referendum -- Aug. 31 -- by arranging a side trip to Portugal. The French president then compounded the mystery by flying back to Morocco for further talks with the king.

After at first refusing to discuss Mitterrand's double visit to Morocco on the grounds that it was a strictly private affair, French officials are going out of their way to deny rumors that it foreshadows any change in France's traditionally even-handed approach to its two former colonies in North Africa.

Foreign Minister Claude Cheysson, who was dispatched to Algiers in an attempt to appease an angry President Chadli Bendjedid, insisted in a radio interview yesterday that the idea of a private visit by Mitterrand to Morocco had originally been broached in January 1983. Cheysson said that the decision to go ahead with the visit -- despite the controversial treaty -- was made to avoid "a crisis" in France's relations with Morocco.

Officials said that the visit had been initially scheduled for the summer of 1983 but was postponed because King Hassan refused to provide military and diplomatic support for France after the Libyan invasion of Chad that summer. At the same time, Qaddafi cut off Libyan support for the Polisario -- a move that foreshadowed last month's announcement of a formal union with Morocco.

French commentators have speculated that, in addition to easing Morocco's problems in Western Sahara, the union with Libya could bolster Hassan's position with the Organization of African Unity. Radical African states had been calling for Morocco's ouster from the organization because of its policies in Western Sahara.

The treaty with Libya, which was formally signed by Hassan and Qaddafi on Aug. 13 in the Moroccan town of Oujda, near the Algerian border, could also have domestic political significance in Morocco, French observers have said. The Moroccan government has been under pressure from Islamic fundamentalists and has faced riots over rising food prices.

French officials have denied reports that Mitterrand asked Hassan to act as a go-between in negotiations with Libya about the removal of Libyan and French troops from Chad. In his radio interview, Cheysson said there was no need for such an intermediary because France was in direct contact with Libya on the subject.

The French foreign minister added that chances for an agreement with Libya over ending the stalemate in Chad had improved during the past few months. French troops were sent to Chad in August 1983 to prevent Libyan-backed rebels from toppling the pro-western government of President Hissene Habre.