After six years in opposition, the Socialists today joined a new government formed by Christian Democratic Premier Francesco Cossiga to give him a stable majority in parliament.

Cossiga's unexpected opening to the left gave Italy its first majority government since 1974 and appeared to offer a period of greater political stability.

The new three-party coalition Cabinet was sworn in by President Sandro Pertini this afternoon, ending one of the country's shortest political crises. It is Italy's 39th government since the end of World War II.

With 340 of parliament's 630 seats, the coalition has a voting majority of 50. Apart from the Christian Democrats with 262 seats and the Socialists with 62 seats, the coalition includes the small but prestigious Republican Party with 16 seats.

The key to the formation of the new coalition was the Socialists' decision to drop their previous demands linking their own participation in a government to that of the powerful Italian Communists. The Communists, who backed a minority Christian Democratic government between March 1978 and January 1979, will remain in the opposition.

The shift in the Socialist position represented a substantial triumph for party leader Bettino Craxi who currently controls about 60 percent of a party that is better known for its divisions than for its unity.

It was also a victory for the more conservative wing of the Christian Democratic Party, a group which is staunchly opposed to giving Cabinet seats to the Communists.

The political payoff for the Socialists, who were in the Cabinet steadily for 12 years beginning in 1962, came in the nine Cabinet posts they were given, including defense and foreign trade. Republicans got three posts. And the Christian Democrats, who kept the key interior and foreign ministries as well as the premiership, had 15. The ruling Catholic party has held the premiership of Italy uninterruptedly since 1945.

The new Cabinet is larger than its predecessor by three positions, with one ministry without portfolio, and two newly created posts for Common Market affairs and for Italy's 20 regions, accounting for the difference.

Under pressure from Pertini, the 51-year-old Cossiga worked quickly to form a new government capable of dealing with a tense international situation and with the pressing problems of terrorism and inflation at home.

There is substantial agreement among the three partners on the need to better coordinate the fight against terrorism, control inflation, and bring about an overall normalization of political life.

According to sources, the chief problem was that of distributing the Cabinet posts. Former premier Emilio Colombo returned to the political limelight as foreign minister. Twelve Cabinet ministers, including Finance Minister Franco Reviglio, were holdovers from the last Cabinet. a record 11 persons from all three parties were given Cabinet posts for the first time. 1