The Soviet Union and Ethiopia established a formal alliance today. In a Kremlin ceremony, the two signed declaration on the "foundations for friendship and cooperation" as well as economic and technical agreements.

The ceremony capped a three-day visit here by Ethiopia's military leader, Lt. Col. Mengistu Haile Mariam, who has reversed his country's long-time reliance on the United States for military and political support in favor of closer ties to the Soviets. No details of the pacts were disclosed but the signing symbolizes Moscow's assumption of the public burden of backing a regime beset by internal insurrections and feuding with its neighbors.

The Soviets and Ethiopians reached a secret military assistance agreement last December, according to Western reports, but there has been nothing in the current talks to indicate exactly what the aid might be. Estimates of the Kremlin commitment, however, have gone as high as $100 million.

Shipments of American weapons to Ethiopia were sharply reduced in recent months and then ended in April after Col, Mengistu and his Provisional Military Council expelled a sizable portion of the U.S. officials there. Some analysts have said that move actually benefitted the United States by releasing it from a relationship that carried more risks than benefits, given Ethiopia's present instability.

In supplanting American influence, the Kremlin faces the considerable problem of reconciling its new alliance and an existing one with Somalia, Ethiopia's neighbor and bitter enemy. The Soviets have already tried to resolve the territorial differences between the two countries by forging ideological links between them. The policy has not succeeded so far and Somalia, where the Soviets have made their biggest overall investment in black Africa, is being courted by moderate states in the region.

The complexities of Ethiopia's volatile internal situation were displayed today while Col. Mengistu was dining at the Kremlin with his Soviet hosts. About 60 Ethiopian students, thought to be supporters of the Eritrean secessionist movement that is fighting an all-out war with the central administration, apparently converged on the Ethiopian embassy. About 200 Soviet police, including a squad of men in helmets and flak jackets, placed a cordon around the building. Ambulances rushed to the scene and one eyewithness said that the authorities appeared to be preparing a siege of the embassy.

After four hours, the incident ended quielty when the students left the building insisting that nothing unusual had occurred. The same version was offered by the Ethiopian ambassador and Soviet officials. One Soviet plainclothesman said that there had been a "meeting of government representatives."

Mengistu has been accorded almost - but not quite - the same honors as other Soviet allies in Africa and the Middle East. The colonel's principal interlocutor was Soviet President. Nikolai Podgorny and he met only once, this morning after the official negotiations were completed, with Communist Party chief Leonid Brezhev.

The declaration on the "foundations for friendship and cooperation" also falls short of the friendship treaty that Moscow has signed with Somalia. The prevailing diplomatic belief here is that the Soviets will go as far as they can in wooing Ethiopia, which now ahs no place else to turn for superpower patronage, but will continue to favor Somalia.

Analysts said it was unlikely that Mengistu would have travelled to the Soviet Union, his first trip abroad since he became head of state in February following a bloody power struggle, if all he expected was rhetorical endorsement. The extent of Kremlin underwriting of Ethiopia may gradually emerge as the jockeying for influence in the strategic Horn of Africa continues.

Col. Mengistu flew to Leningrad this afternoon and in expected to leave for home Saturday. A communique published then may give further hints to the scale of Moscow's latest African foray.

(Radio Ethiopia, monitored by Reuter in Kenya, quoted a government spokesman as saying reports of large-scale killings in Addis Ababa last weekend were "false and completely baseless." In London, the Daily Express said its correspondent, Peter Mason, was ordered out of Ethiopia.)