Morocco's King Hassan II, the principal U.S. ally in northwest Africa, faces an expanding two-front war in the Western Saharan territory he annexed nearly six years ago, with the growing participation of the neighboring desert state of Mauritania on the side of Polisario guerrillas.

Mauritania's change of policy is the most threatening move in Hassan's war with the guerrillas who seek independence for their Saharan Arab Democratic Republic. It joins Mauritania with neighboring Algeria and Hassan's archenemy, Muammar Qaddafi of Libya, into an informal alliance on the side of the guerrillas.

But it also complicated Morocco's desert war of attrition against the Polisario. Until this spring, the guerrillas operated from sanctuaries in Algeria. A southern front that is now opened with the guerrillas also operating from Mauritanian bases puts the Moroccan Army at a serious disadvantage.

A combination of adverse diplomatic and apolitical changes is likely to prompt Hassan to turn to Washington for additional military assistance. More important, the protracted desert war may sap Morocco's resources to a point at which the king's government could be threatened by internal difficulties.

The Mauritanian shift was precipitated by an incident that began on March 16, when two Mauritanian political exiles, both former Army officers, secretly entered their homeland from Senegal. In a brief shootout in Nouakchott, the Mauritanian capital, they and several accomplices unsuccessfully attempted to overthrow President Khouna Ould Haidallah.

Haidallah blamed Morocco for the incident, broke relations with Hassan's government and executed the two leaders of the coup attempt, along with two other accomplices in late March. Shipments of Algerian arms began arriving in Nouakchott, and Polisario attacks against Moroccan forces in the Sahara from Mauritanian bases were stepped up.

The Mauritanian prime minister flew to Tripoli and announced that Libya's closed cultural center in Nauakchott would be reopened and detained pro-Libyan Mauritanians released.

Qaddafi responded by proposing that Mauritania and the Polisario movement, which Libya supports with arms and funds, should merge.

Qaddafi announced April 21, following a visit to Nouakchott, that Mauritania had "agreed on the union when objective conditions permit." Mauritanian leaders, however, said that Mauritania had "politely" rejected the union proposal and was noncommittal toward a further Qaddafi suggestion for a new "revolutionary alliance" of Libya, Algeria, Mauritania and the Polisario.

Before leaving Nouakchott, Qaddafi also predicted an "impending Arab counteroffensive to liberate" Israeli-occupied Arab territory. He said "preparations" were also under way for an attack against "U.S. forces and their agents" in Somalia, where the United States has obtained port and air base facilities.

State Department Africa-watchers, while publicly accepting Morocco's disclaimer of responsibity in the coup attempt, say privately that Rabat must have at least known of the plan in advance. They agree its intent was to halt the widening of the Western Sahara war by eventually expelling the Polisario from Mauritanian bases.

These new bases, from which the highly mobile Polisario columns already are launching attacks on the Moroccans further north, are located in the so-called Tiris region. This is the southern slice of the western territory once known as Spanish Sahara, which in 1975 was divided between Mauritania and Morocco.

Initially, Mauritania fought with the Moroccans against the Polisario attempts to claim the entire territory. In 1979, however, Mauritania withdrew from the war and, despite Moroccan attempts to prevent it, virtually ceded its portion of the partitioned terriotory to the Polisario.

Still, until this spring, the Polisario guerrillas' only main rear base was in the north, near the Algerian oasis of Tindouf. The opening now of a southern front, out of bases in Mauritania, places Hassan's 50,000-man, U.S. and French-supplied forces in the middle of a military nutcracker.

By late March, Polisario raiding parties armed with Algerian and Libyan supplied Soviet weaponry launched a series of attacks against the Moroccan-fortified defense line near Guelta Zemmour.

The 500-mile long desert line is equipped with U.S. supplied sensors, monitored from the air by helicopter gunships, Mirage F1s, U.S. Northrop F5s and newly acquired Rockwell OV10 Bronco counterinsurgency aircaraft.

A desert war of attrition like the one Morocco has fought against the Polisario would be difficult to win without direct attacks on Polisario sanctuaries in Algeria, or supply lines from Libya, Royal Moroccan Army officers believe. But such attacks would likely trigger full-scale war in North Africa.

Now firmly in control of Chad, many African observers believe Qaddafi's next major military adventure will be in the Western Sahara, where he has supported the Polisario nationalists since their first uprising against Spanish troops before partition in 1975.