Spaniards go to the polls Sunday in an election in which Prime Minister Felipe Gonzalez is heavily favored to win a second term and the main outstanding question is whether he will retain a majority in Congress.

Even if his Socialist Party fails to win the 176 seats needed to form a majority in the Congress of Deputies, it is still expected to have the largest bloc of votes and to be able to rule with the tacit agreement of one or more opposition parties.

The election has been upstaged by the nation's frenzy over its national soccer team's performance in the World Cup competition in Mexico.

The seemingly foregone result of the election contrasts with the unexpected progress of the national soccer squad. Within four hours of the closing of the polls at 8 p.m. here the Spanish team will be playing Belgium in Puebla and most of the nation will be glued to television sets for the midnight live coverage.

A wave of terrorist attacks continued with the explosion of a bomb in the garden of a military housing complex. The explosion, which police said appeared to be the work of Basque separatists, injured no one, United Press International reported.

Last night political leaders attempted to revive flagging interest in the poll.

In Madrid, rallies were held across the city. The Communists held their meeting in the main bullring and the Socialists staged theirs in a newly inaugurated rock concert amphitheater. The centrists met in the colonnaded Plaza Mayor, the heart of old Madrid, and the conservatives held a rally in a rich suburb.

Gonzalez warned that a failure to return the Socialists to power would mean a "step backward." The conservative opposition leader, Manuel Fraga Iribarne, told his supporters that his center-right coalition, called the People's Coalition, was the only group capable of turning socialism out of power.

Gonzalez, a 44-year-old former labor lawyer, won by a landslide in 1982, gaining 202 seats in the 350-member Congress of Deputies. Opinion surveys, which are prohibited for a week before election day, indicated earlier in the campaign that Gonzalez would lose seats and might come close losing to his majority.

Fraga, who in the 1960s served Generalissimo Francisco Franco as information and tourism minister, was also forecast to lose ground in the opinion polls a week ago. His coalition, which has mixed a law-and-order campaign message with an economic platform of lower taxes and more private enterprise, is said to be unlikely to hold the 106 seats it won in 1982.

The polls have forecast gains for the Communists, who won four seats in the last elections, for the nationalist parties of Catalonia and the Basque country and for a centrist party headed by former prime minister Adolfo Suarez, who has run an effective populist campaign.

Both the Communists and Suarez, who was prime minister between 1976 and 1981 and the chief architect of Spain's transition from the Franco dictatorship to democracy, have attacked Gonzalez's Socialist government for its austere economic policy and for its caution on social issues.

Gonzalez has replied by emphasizing the democratic stability of the past four years, the success of his policy aimed at streamlining the economy and prospects of growth.