Social Democrats demanding an accelerated liberalization of the economy pulled out of the Socialist-led government of Prime Minister Mario Soares today, throwing Portugal into political upheaval a week before it enters the European Community.

The crisis provoked by the junior partners in the two-year-old coalition threatens a collapse of the center-left government and could delay economic recovery for Europe's poorest country, possibly depriving it of the immediate benefits of EC aid, observers said.

Social Democratic leader Anibal Cavaco Silva said the party was quitting the government because of the Socialists' failure to implement pressing economic reforms. He said the seven Social Democratic ministers would not abandon the 16-member Cabinet until June 13, the day after Portugal is to sign the EC membership treaty.

The move also reflects the two government parties' backing for rival candidates in presidential elections set for December and factional struggles within the troubled Social Democrats. Cavaco Silva, a hard-line conservative, was elected their leader at a special congress two weeks ago in the party's third leadership shake-up this year.

The future of the government now rests with President Antonio Ramalho Eanes. He can order the coalition to remain in office as a caretaker, appoint an interim Cabinet or call early national elections not otherwise due to take place until 1987. The Social Democrats have said they will not support a minority Socialist government.

Soares forged the alliance with Social Democrats after elections in April 1983 to form Portugal's 15th government since the 1974 revolution that overthrew fascism. It is the longest-surviving democratic government and the first to command an overall majority in the 250-seat legislative assembly. The Socialists hold 101 seats and the Social Democrats 75.

But the swing of the Social Democratic leadership to the right has aggravated tensions within the coalition and led to mounting Social Democratic demands for faster reforms toward modernizing backward industry and agriculture in preparation for EC entry.

Cavaco Silva's tough stance appears calculated to please hard-line supporters who favor severing ties with the Socialists and reestablishing their previous alliance with the right-wing Christian Democrats.

Cavaco Silva blamed the Socialists. "It is in fact the Socialists who have broken the coalition accord and made the government unworkable," he said.

He accused Soares of stalling on unpopular reforms in order not to alienate labor support in the presidential election. Soares is widely expected to be the Socialist candidate and Cavaco Silva has said he would accept the Social Democratic nomination. Eanes cannot run for a third five-year term.