Hidden away in Prime Minister Felipe Gonzalez' wardrobe is a shirt that was ruined nearly 20 years ago by a cigarette burn. It is a sentimental relic of the Spanish leader's days in the anti-Franco resistance.

The story goes that late one night Gonzalez was climbing the stairs to his fourth-floor apartment in his home town of Seville, in the days when he was starting as a labor lawyer and was newly enrolled in the then-banned Socialist Party. He had a cigarette dangling from his lips and was carrying a portable photocopying machine in both hands.

The cigarette fell onto his shirt but Gonzalez struggled on up the stairs rather than risk dropping the precious machine. The young activist feared both damaging the photocopier and waking his nosy neighbors, who were unaware of his clandestine propaganda activities.

The prime minister risked his shirt again Wednesday, metaphorically this time, in a referendum on whether Spain should continue its membership in the North Atlantic Treaty Organization.

Gonzalez put his political future on the line with his determination to have Spaniards vote yes. He confounded adverse opinion polls and won by a 52-to-39 percent vote that was as decisive as it was unexpected.

Jose Rodriguez de la Borbolla, a friend from Seville days and now the area's top Socialist official, said afterward that "Felipe was always a winner."

Two decades ago Gonzalez already was noted for his persuasive powers and his widening circle of friends believed that he would climb high in the Socialist Party. The widespread belief in Spain now is that the 44-year-old prime minister will stay at the top for the foreseeable future.

The referendum result is viewed as a watershed that has definitively ended Spain's centuries-old isolationism and opened new horizons for the country as a full-fledged member of the western community. But the plebiscite is seen also as a milestone in Gonzalez's own brand of moderate and pragmatic socialism.

The new horizons seemed clear as Spain's four stock exchanges posted record rises in the wake of the pro-NATO vote. The bullish trend, spearheaded by foreign investors, reflected strong business confidence in Spain's growth potential following the resolution of its political and foreign policy ambiguities.

For Gonzalez, the result signified a major step in his effort of reeducating the once radical Spanish left and of steering it along the path of social democracy.

Seven years ago, he forced the Socialist Party to strike out the Marxist label from its declaration of principles by briefly resigning as party leader. As prime minister, he has over the past three years forced the party and the socialist labor movement to accept orthodox monetarist policies that have been bluntly termed "Reaganite" by left-wing critics.

In the referendum campaign, Gonzalez argued that Spain's Socialists should drop neutralist attitudes and be wholly supportive of the West. Although he was himself a leading opponent of Spain's entry into NATO four years ago under a previous center-right government, Gonzalez now argued that alliance membership was the "logical consequence" of Spain's entry at the start of this year into the European Community.

Gonzalez lost some of the Socialist vote in the referendum, but he won majority backing for his message of modernity and moderation. Radicalism, he frequently says, has a diminishing constituency in Spain, both on the right and the left.

Gonzalez managed to break down Spain's traditional distrust of bloc politics with somber warnings of "economic uncertainty" and "political instability" if a majority voted for withdrawal.

The chairmen of Spain's major banks had issued a joint statement that stressed the "incalculable" economic consequences of an alliance withdrawal.

Now, the business mood is distinctly upbeat. A symbol of the future will be the start next month on construction of a major AT&T plant outside Madrid that is to export $220 million worth of microchips by 1990. Other multinational high-tech projects have been announced recently in the northeastern region of Catalonia. In the bay of Algeciras, Bechtel and Citibank are carrying out a feasibility study to establish the zone's prospects as a potential superport. The surrounding southern region of Andalusia has shown agribusiness and tourist potential.

With the NATO hurdle behind him, Gonzalez has gained valuable breathing time before fall general elections. This allows him to work to restore party unity -- although no Socialist of importance left the party in disagreement with his pro-NATO stand.

By election time, government officials and independent economists predict, the gross domestic product, which grew at 4 percent -- two points above earlier forecasts -- in the last half of 1985, could be moving into top gear. This would allow a marked improvement in Spain's high jobless level.

Jorge Hay, head of research at a top Spanish bank, estimates that the fall in oil prices and the dollar could halve Spain's trade deficit, from $4.3 billion in 1985. Hay's concern is that the country's current account surplus, one of the highest in Europe last year, could become "embarrassingly large."

With the stock market indexes at the end of referendum week the highest in 12 years, it appeared to many observers that Gonzalez was set to ride a new economic and political bonanza after gambling all on the referendum issue.