SPAIN'S VOTE to remain in NATO -- in defiance of all opinion polls and predictions -- has implications far beyond military matters. Spanish withdrawal would have hurt the alliance, but not crucially. It would have been more important as a step back toward isolationism by a country whose history over the past generation has been very different from that of its western European neighbors. And that, at the end of a heated referendum campaign, was the issue: whether to retreat or to keep advancing toward a common destiny with the other Atlantic democracies.

Change has overtaken Spain with awesome speed. Under Francisco Franco, the last survivor among the fascist dictators of the 1930s, it remained very much out of the stream of European developments. Franco wanted it that way, and the other governments shunned Franco. But since his death in 1975, the country has embraced the democratic tradition with great conviction. In January it took another long step toward its neighbors by joining the Common Market -- a decision that promises great things for Spanish prosperity, but at a substantial cost to the comfortable and accustomed old ways of doing things. If Spanish voters had decided to take a step backward in yesterday's NATO referendum, it would have been understandable. Instead, they chose to persevere.

One reason was the character of the opposition to NATO membership, led by pacifists and the Communist Party. A larger reason was the vigorous and skillful leadership of the Socialist prime minister, Felipe Gonzalez, a man who had changed his own mind on the subject. As a candidate in the last election, he had been against the alliance, but in power he became convinced of the importance of staying in. He has succeeded in taking his party and now his country with him on this change of course. The vote is, for him, a triumph that leaves him in an extremely strong position for the national elections later this year.

In supporting Spain's continued membership, Mr. Gonzalez set three conditions. First, Spain would continue -- like France -- to stay out of NATO's integrated command structure. Second, it would continue to bar nuclear weapons from Spain. Third, Spain will seek the "progressive reduction" of the U.S. military presence there. All three of these conditions can be met without great difficulty. The first two continue present policy. As for the third, the United States and Spain agreed last December to discuss a reduction in the American forces stationed there.

NATO is a good deal more than a conventional military alliance. By their vote to remain within it, the Spaniards have strengthened their commitment not only to their friends but to the common defense of the democratic principles for which NATO has stood for nearly four decades.