Opinion polls published in two Madrid newspapers today forecast a landslide victory by the opposition Socialist Party in national congressional elections next week and the collapse of the Union of the Democratic Center, which has governed Spain during the democratic transition from Francoism.

The polls, the last to be published before next Thursday's voting, predicted a Socialist majority of up to 40 seats -- a far greater swing to the left than previously indicated.

The projection of a Socialist triumph came against a background of minor terrorist bombings and continuing unease over rightist military plotters that was fueled today by the urgent transfer of four officers allegedly connected to a putsch conspiracy.

In a survey of 18,000 voters published by the newspaper El Pais, the Socialist Party received 42 percent of the support and the conservative Popular Alliance Party received 21 percent with just 5 percent for ruling Union of the Democratic Center.

According to the poll, Prime Minister Leopoldo Calvo-Sotelo would fail to get reelected, along with 11 fellow members of the outgoing Cabinet, among them the foreign affairs, interior and treasury ministers.

A separate poll of 7,000 voters that was published by the newspaper Diario 16 confirmed the 42 percent support for the Socialists and showed the Popular Alliance with 18 percent and the Union of the Democratic Center with 9 percent of the vote.

The indication in both polls was that the Socialists could have as many as 217 seats in the 350 member congress compared with the 121 seats they won in the last elections held in 1979. The two papers' polls estimated that Popular Alliance would win between 69 and 107 seats, against just nine in the 1979 elections. The ruling Democratic Center, which held 167 seats to win the last elections, were shown to have all but disappeared in the polarization between the Socialists and the conservatives. The polls indicated they would win between 12 and 18 seats.

The newspaper polls were published as the official Army Gazette today announced the immediate transfer of three lieutenant colonels and a major from their posts in Madrid and Valencia to bureaucratic assignments in outlying provinces. This brought to nine the number of officers who have been summarily transferred in recent days in what political sources say is a Defense Ministry attempt to isolate known rightist hard-liners in the military.

Calls for such action have been a consistent feature of the election campaign ever since the government announced at the beginning of the month that it had foiled a conspiracy for an election-eve military coup. Three colonels have been charged with plotting a military rebellion that the government claims involved the takeover of Madrid and the planned bombardment of the Zarzuela Palace, the residence of King Juan Carlos.

Coup jitters were dramatically underlined earlier this week when the 2,500-strong palace guard threw a defensive cordon around the Zarzuela residence on the northwestern outskirts of Madrid following what a palace spokesman said was an anonymous tip that a coup was imminent.

Defense Undersecretary Eduardo Serra said today in a state radio interview that rumors of coups were part of a campaign to spread alarm before next week's elections. Many Spaniards recall that the last left-wing administration to be elected in Spain was overthrown by Francisco Franco in the 1936-39 Spanish civil war.

Further adding to the tension has been increased activity by the Basque separatist group ETA. Police believe ETA was responsible for 20 small bombs that exploded in the Basque country Wednesday night and early Thursday when Socialist leader Felipe Gonzalez was touring the area. At the weekend small blasts that likewise caused damage but no injuries were reported in eight cities.