President Ramalho Eanes yesterday offered the political parties of this fredgling democracy a last chance to come up with a government before he dissolves its first parliament and calls new elections.

This was clearly a threat to strip former Premier Mario Soares Socialist Party of its dominant role in Portuguese political life if it persists in its refusal to go along with the president's efforts to resolve the political crisis.

Most of the public preceives the situation as a test of wills between Eanes and Soares. The president appears to have the country largely behind him. The outcome of the struggle is likely to determine whether parliament or the president will be predominant in Portugal.

The Socialists, who were regarded as the saviors of the republic from a Communist takeover in 1975, would now almost certainly be the heaviest losers in elections held under present circumstances. The Communists and the right-wing Social Democratic Party would gain at Socialist expense.

The president addressed the nation last night for the first time since parliament rejected the nonparty government of Premier Alfredo Nobre da Costa a week ago. It was named by Eanes after the breakup of a coalition government headed by Soares.

Eanes appointed that government without consulting the political parties, a move Soares has denounced as a violation of the constitution and of democratic pratice.

The president appeared to offer Soares a small olive branch by seeming to admit that it was a mistake not to have sought party support for Nobre de Costa. Nevertheless, while he mentioned no party by name, Eanes' speech was full of phrases that could only be seen as attacks on Soares' party.

No party, Eanes said, can "achieve and guarantee democracy by itself."

No Socialist spokesman reacted to the presidential address.

The Socialists won 35 percent of the vote and 107 seats in the 263-member parliament in 1976 in the first elections under Portugals new constitution. The Social Democrats, the next largest party, won 24 per cent.

Most analysts have concluded that the positions of the two parties would be reversed in any elections dominated by the present crisis. For a number of complex legal reasons, new elections could not be held before next March at the earliest, however.

Among other things, there must be a new election law and the updating of the voter registration rolls to include the 250,000 persons who have turned 18 since 1976 and the 750,000 who fled Angola after it gained independence from Portugal. The refugees generally are expected to vote massively for the Social Democrats.

Eanes hinted broadly that he thinks Parliament is deliberately dragging its feet on both those measures to prevent elections before its term expires in 1980.

Eanes' aides have been insisting that he has no ambitions of turning Portugal into a presidential republic like the United States or France.

He made it clear, who was the boss in Lisbon this week, however, by refusing to heed appeals from party leaders to meet urgently with him to discuss the crisis before addressing the nation. By that simple device, he reduced the parties to virtual silence for a week. His spokesmen said he wanted to see no outsiders because he was too busy "reflecting."

In his speech, he said he prefers formation of a coalition government by Parliament. But he said that he, as president, would determine whether such a government is "adequate to deal with the political situation."

If no new coalition can be formed, Eanes said, he would name an independent premier who would try to enlist broad parliamentary support by forming a Cabinet including ministers from the political parties. The Socialists forbade their members from joining the Nobre da Costa government.

If such an independent premier could not enlist party support, Eanes said, he would name another premier with the express mission of getting the needed election laws out of Parliament before it is dissolved for new elections.

The more Soares has protested the president's various moves, the more he has seemed to cast himself as a special pleader for the narrow interests of the Socialist Party. A number of prominent Socialists, including three former Socialist Cabinet ministers, have quit the party in recent months to disassociate themselves from Soares.

The party is widely criticized from all sides for having turned itself into a patronage machine to place its followers in the civil service, the media and nationalized business and industry.

The Socialists also are accused of having sacrificed the party's long-term political objectives for such tactical considerations as gaining labor peace by buying off the Communists. The Socialists are said to have deliberately failed to implement laws designed to roll back illegal Communist led occupations of large tracts of farmlands in southern Portugal.