Portuguese Socialist leader and former premier Mario Soares declared victory in national elections as his party emerged as the largest in parliament early today, ending three years of conservative rule.

Despite their gains, the Socialists fell more than 20 seats short of a majority in the 250-seat National Assembly and almost certainly will have to form a coalition to their right.

Computer projections based on four-fifths of returns gave the Socialists as much as 38 percent of the vote and 102 seats in the assembly, up from 66 in the previous parliament elected in October 1980.

In a televised news conference early today, Soares stressed that he would not seek to rule with a minority government but would negotiate a stable majority coalition with forces that represented "democratic socialism."

He did not specify any parties, but it was clear that the only plausible option for a coalition was with the center-right Social Democrats, who had led the previous ruling coalition.

The conservative coalition that had held an absolute majority of 134 seats was projected as winning no more than 104 seats. Of the two main parties in the coalition, the Social Democrats were forecast to elect 74 deputies, and the right-wing Christian Democrats were predicted to suffer a drop in their representation from 46 seats to 29.

The projections showed the pro-Soviet Communist Party with a slight increase, from 39 seats to 44, replacing the Christian Democrats as the third largest party.

The result marked a personal triumph for Soares, 58. He steered Portugal through its first years of revolution after the overthrow of a right-wing dictatorship nine years ago and then was dismissed by President Antonio Ramalho Eanes when the second of his short-lived minority governments collapsed in July 1978.

Soares was then forced to fight a bitter leadership struggle within his party when left-wingers sought to blame him for two crushing election defeats to the conservative coalition in 1980.

His party became the front runners in yesterday's election after the coalition fell into disarray as feuding factions forced the resignation of Social Democratic prime minister Francisco Pinto Balsemao last December.

Soares, faced with forming the 15th government since the 1974 coup, can put together a parliamentary majority only by joining the Social Democrats, led by Balsemao's successor, former university professor Carlos Mota Pinto. The Socialist leader has made it clear he is not prepared to head a third minority government and has ruled out any alliance with the Communists.

Soares is determined that the next government will be the first in Portugal's democratic history to survive its four-year term.

He is prepared, he says, to risk drawn-out negotiations over the formation of a coalition. Such a delay would stall urgent measures to ease a steadily worsening recession. But the Socialists are not prepared to take sole responsibility for an inevitably harsh austerity budget.

Inefficient management by 14 short-lived governments has allowed the economy to slide dangerously downhill, with the 1982 balance of payments deficit standing at $3 billion and a foreign debt of $13 billion. Inflation runs at 23 percent annually while the escudo suffers constant devaluations. Soares admits the recession will force his party to manage the economy like stern conservatives for at least three years.

In the aftermath of the 1974 revolution, Washington backed Soares as the safest guarantee against the Soviets gaining a Cuba-like toehold in southern Europe, supporting the country during its first fragile years of democracy with hefty inputs of aid and technical assistance.

According to western diplomats here, a Socialist-led government in Lisbon would favor U.S. policy in southern Africa. They reason that Soares has the socialist credentials to strengthen Portugal's ties with its former colonies, giving Marxist Angola and Mozambique the opportunity they clearly seek to lessen dependence on the Soviet Bloc and move closer to the West.

Soares' links with Washington could also ease forthcoming negotiations on the renewal of the lease on a strategic U.S. air base on the mid-Atlantic Azores islands. The Reagan administration is also seeking its first bases in mainland Portugal.