Ethiopia yesterday threatened to invade Somalia unless, in effect, the Somali-backed guerrilla war ends inside the disputed Ogaden.

In a written statement, Ethiopian Ambassador Mengiste Desta said, "Should Ethiopia be attacked again in one form or another, this time the battle will not be fought within the Ethiopian border."

"Under what early or heavenly rules should Somalia's border be sacrosanct and not Ethiopia's" he asked at a news conference here.

The Ethiopian warning reflected growing anger in Addis Ababa at the continuing guerrilla war in the Ogaden despite the Cuban and Soviet-led victory last month over regular Somali troops.

After a temporary hiatus following the formal Somali withdrawal from the Ogaden in early March, guerrilla operations were reported to have resumed.

The Mogadishu-backed Western Somali Liberation Front charged that Ethiopian aircraft had bombed Somali border villages in what appeared to be reprisal raids.

The Ethiopian ambassador said Somalia seemed "unable to learn from its humiliating defeat - and his threat poses a serious problem for President Mohammed Siad Barre's government in Mogadishu.

Even withdrawing mainforce Somali units from the Ogaden was resented by many northern Somalis despite the fact that the troops had suffered an obvious defeat.

These northerners and the northern-dominated Liberation Front have accused President Siad Barre of betraying the cause of reuniting ethnic Somalis on both sides of the border.

The Mogadishu government - which has been reshuffled since the defeat to take on a more southern configuration as the president relies increasingly on his own Marehan tribe - has felt obliged to back a continuing guerrilla war.

That appears to be the minimum price if the restive northerners are kept in line at a time when the government has just weathered a coup attempt.

Observers here doubted that the Cubans and Soviets would participate actively if the Ethiopians carried out their threat to invade Ethiopia.

The Soviets were credited generally with wanting to avoid any accusation of violating African frontiers. They have justified their presence - and that of the Cubans - in Ethiopia on grounds that they were helping a sovereign state protect its territorial integrity, one of the cardinal principles of the Organization of African unity.

Diplomats here believe, however, that in the final stages of the Ogaden fighting the Ethiopian army showed enough improvement to be able to handle an invasion. The Somali forces lost much of their heavy equipment in the fighting and serious problems continue, as last Sunday's abortive coup showed.