A bitter, divisive and confusing campaign on continued Spanish membership in the North Atlantic Treaty Organization concludes in a referendum Wednesday, and polls show the outcome remains in doubt.

Politicians and analysts here agree that the vote has much more to do with domestic politics than with actual membership of the alliance.

It is being held because Socialist Prime Minister Felipe Gonzalez promised in his election campaign four years ago to put the issue of NATO membership to a vote.

At that time, he was hostile to Spain's entry into the alliance, which took effect prior to his election in 1982, and it was clearly understood that the referendum would be held to pull Spain out. One of Gonzalez's first acts in office was to freeze Spain's integration into the military structure of the alliance.

Since then, however, Gonzalez has changed his mind on the issue of membership (although not on military integration) but has stuck by his pledge on the plebiscite. Now he is campaigning to persuade his compatriots to vote in favor of NATO.

The referendum campaign has polarized Spaniards into voting for or against the government -- or into abstaining, which the conservative opposition says is a way of demonstrating support for NATO and at the same time registering a protest against the Socialist government that insisted on putting the issue to a vote.

Popular skepticism about the stand taken by the main political parties and about the purpose of the referendum remains widespread, and independent and government polls show that as much as 25 percent of the electorate is still doubtful about how to vote or even whether to vote.

"At this present moment, the 'no' to NATO vote is leading by four percentage points," a senior government official said earlier this week, "but the gap is closing fast." Independent surveys published this week in two Madrid news magazines gave opposing results: one was similar to the government's, while the other measured a five-point lead for the "yes" vote, favoring continued NATO membership.

The conservative opposition, whose leadership consistently has backed Spain's presence in NATO, argues that the referendum is unnecessary because the legislature already has endorsed membership and that the plebiscite sets a dangerous precedent. Right-wing leader Manuel Fraga has called on voters to abstain.

Gonzalez has staked his political reputation on the plebiscite. Worried over adverse polls, the 44-year-old leader has been pressing in recent days to win over the undecideds.

"I am proud to be swimming against the current," he told thousands attending a rally in the southern city of Jaen last weekend, because it is "in the interests of Spain."

Ignoring his previous opposition to NATO, Gonzalez argues passionately that Spain has to emerge from a centuries-old isolationism and take its rightful place in the defense and security system of the West. Saying that NATO ensures progress, democracy and freedom, he warns that if Spain should reject the alliance there would be "an international crisis of confidence" and foreign investment would dry up.

The opposition is treating the referendum as a primary for national elections that are due to be held later this year. It views Gonzalez's decision to stage the NATO vote as an attempt to hold a personal plebiscite.

In sponsored television spots, the conservatives are urging voters to stay away from the polls and reminding the electorate of issues such as crime, prices and unemployment that have come to the fore during Gonzalez's term.

The bitterness of the debate has taken its toll. Javier Pradera, the chief editorial writer of the influential newspaper El Pais, resigned last week because readers had protested that he was organizing manifestos calling for a vote in favor of NATO.

The lineup against the alliance is a mix of political positions. It includes Communists and ecologists as well as erstwhile Socialist voters. Conservatives, too, intend to vote against the alliance in the referendum, a trend that has prompted right-wing leader Fraga to insist that he is seeking abstention rather than a "no" vote.

The anti-NATO platform is, at one level, a gut reaction against military blocs. Spain stood on the sidelines of both European world wars in this century, and the Pyrenees mountain range that divides it from France has cut it off from East-West issues.

Underscoring this, the dominant slogan of the "no" campaign is "Leave Us in Peace," and speakers at its meetings call on voters to back neutrality and oppose American bases in Spain as well as NATO. A number of prominent European pacifists, including Britain's Edward P. Thompson, have joined the campaign. "The eyes of the world are on Spain," he told a huge rally in Madrid 10 days ago. "You are an example to us all."

Opposition ranks have been swelled by Gonzalez supporters who are disillusioned with the government's economic austerity policies. The referendum provides the opportunity of voting against the government although the same "no" voters would probably vote in favor of Gonzalez in national elections.

Aware of the domestic political intrusions into the NATO campaign and of the effects of decades of isolationism, Gonzalez has been working overtime.

In a recent radio phone-in program he explained to listeners how NATO came into being, what the Berlin Blockade of 1948 was about and why the Soviet invasion of Czechoslovakia in 1968 marked a watershed. Gonzalez is spreading a dual message. He is telling conservatives that a "no" vote will lead to Spain's withdrawal from the alliance, and he has been dropping hints to his supporters that a defeat in the referendum could lead to his own withdrawal from politics.