A surprise visit to Romania by Soviet Foreign Minister Andrei Gromyko could form part of a Kremlin attempt to reassert authority over its most maverick East European ally, Western analysts said today.

The virtual breakdown in detente has clearly increased the pressure on Romanian President Nicholae Ceausescu, 62, to modify his country's independent foreign policy stance. His latest in a long series of gestures has been his refusal, alone among Soviet Bloc leaders, to support the Soviet invasion of Afghanistan.

Western diplomats contacted in the Romanian capital Bucharest said Gromyko's two-day visit, which ended today had all the signs of being hastily arranged.

Gromyko, a full member of the Soviet Politburo, had three lengthy meetings with Ceausescu. He is belived to have warned the Romanian leader of the need for political and ideological unity at a time of frigid East-West relations.

Gromyko has been chosen before for trouble-shooting missions to Romania. His last visit to Bucharest was in October 1978, when he is understood to have expressed Soviet annoyance at the warm reception given to the Chinese Communist Party Chairman Hua Guoferg.

As in 1978, Ceausescu has given little hint that he is prepared to back down on substantive issues. A joint Romanian-Soviet communique issued after the talks pointedly failed to express overt support for the Soviet Union's intervention in Afghanistan.

Ceausescu did, however, agree to include a phrase blaming worsening international relations on "unresolved international questions, the interference of imperalist forces in the internal affairs of other states, and political force and the threat of force in international relations."

"It's the old Romanian tactic when under pressure from the Russians of appearing to take one step back after taking two steps forward," a Western diplomat commented.

In the last weeks, Ceausescu has made clear that he believes the Soviet intervention in Afghanistan also could have serious implications for Romanians "to rise as one man to defend their revolutionary achievements and independence should the need arise."

In a major speech on Jan. 17, he said Romania would now pay special attention to strengthening its defense capability by equipping its 180,000 strong army -- which relies on increasingly obsolete Soviet-made material -- with modern weapons and improving the military training of young people and workers.

In the past, Ceausescu has proved a shrewd judge of Kremlin thinking. While his displays of independence undoubtedly have annoyed the Kremlin, they hardly have constituted a threat to its security. Unlike Czechoslovakia in 1968, there never has been any attempt to dismantle tight Communist Party control in Ceausescu's Romania.

In an attempt to keep his options open, the Romanian president received U.S. Under Secretary of State David Newsom last weekend and conservative West German opposition leader Franz Josef Strauss earlier this week. Romania also has maintained friendly relations with the Chinese, the Israelisand the Egyptians.

Ceausescu, who came to power in 1965, has stepped up his defiance of the Kremlin in recent years. In November 1978, he publicly refused to go along with the Soviet proposal for an increase in Warsaw Pact Defense spending and last year he condemned Vietnam's invasion of Cambodia.

Romania failed to vote in the United Nations General Assembly debate on Afghanistan at which the Soviet intervention was condemned by a 104-to-18 vote. Ceausescu, however, made it plain that he was opposed to the Soviet action by making critical remarks about "hegemony," "domination," and "the extension of spheres of influence."