Spanish socialist leader Felipe Gonzalez promised today to "faithfully carry out the duties of prime minister, with loyalty to the king, and to uphold the constitution," in a brief swearing-in ceremony as Spain's new prime minister.

The formal investiture of the 40-year-old Gonzalez, the first leftist to head a Spanish government since the country's civil war nearly half a century ago, followed congress' endorsement of his candidacy after midnight today. His Socialist Party carried 202 of the 350 congressional seats in lat month's national elections.

Gonzalez's swearing-in ceremony took place before King Juan Carlos at the Zarzuela Palace on the outskirts of Madrid and was seen as evidence that Spain's transition to democracy following the death of dictator Francisco Franco seven years ago is now complete. When he opened the new socialist-dominated legislature last week King Carlos noted that the changeover of governments was the "essence of democracy."

The accession to power of Gonzalez, a labor lawyer and the son of a Seville farmer, was also seen as an indicator of how swiftly, but cautiously, the country has evolved in its democratic transformation.

Manuel Fraga, 60, once Franco's powerful information minister and now Gonzalez's main parliamentary opponent as head of the Popular Alliance Party, paid tribute yesterday to Gonzalez for his moderating influence on the Spanish left. But the conservative leader charged in his speech in parliament that the "maximum program" of the Socialist Party included Marxist precepts such as "the possession of political power by the working class."

Fraga then drew catcalls from the socialist benches when he said that the new government's stated opposition to military links with the North Atlantic Treaty Organization constituted the "first success of [Soviet leader Yuri] Andropov."

Gonzalez angrily rejected Fraga's charge, but he nevertheless reiterated that one of the first moves by his new government when it meets next week would be to freeze negotiations in Brussels aimed at the entry of Spain into the Western alliance's integrated military command.

Gonzalez also reaffirmed a pledge made during the election to hold a referendum on whether Spain should withdraw from NATO, but he resisted pressure to name a date.

"We will not be hurried into a decision on Spain's possible NATO withdrawal and we will decide as a government when to hold a referendum without anybody fixing a date for us," Gonzalez said.

While the new government is expected to be daring in its foreign policy, Gonzalez has stressed moderation for internal policies, particularly on the economic front.

This was reflected in his choice of Cabinet members who will be sworn into office Friday. The 17-member team includes nine economists, most of whom have served in senior posts in the previous administration and in business. The stewardship of the economy goes to Miguel Boyer who stands well to the right of the Socialist Party and has worked closely with oficials of the outgoing centrist government.

A striking feature of the Cabinet is its youth. The oldest member is career diplomat Fernando Moran, the new foreign affairs minister, who is 56; the youngest is 34-year-old Labor Minister Joaquin Almunia. The average age of the members is 41, one year older than Gonzalez.