A sense of history in the making swept over the Iberian Peninsula today as the doors of Europe finally were opened to Spain and Portugal, sweeping aside long-held feelings of inferiority and isolation and bringing new expectations of a modern future.

"A historic frustration" has come to an end, said Spanish Foreign Minister Fernando Moran on his return from Brussels, where the Common Market early this morning agreed to extend membership to Madrid and Lisbon after years of debate.

"Spain is now where it rightfully belongs," Moran said.

In Lisbon, a jubilant Prime Minister Mario Soares predicted that "Portugal will be a completely different country within five years -- a much better one for us all to live in."

Once the agreement is signed and ratified by the European parliaments, tariff barriers between Spain and Portugal and the 10 current member countries will end gradually over a period of seven years, expanding their markets.

But in the view of many, the more important benefits will be political ones. In both Iberian capitals, joining the European Community was perceived as a mix of a coming of age and a graduation ceremony, or, more exactly, as an assurance that both countries were finally deemed worthy to join a select fraternity open only to the successful.

For Portugal, smaller, more backward and with fewer expectations, it was more obviously a case of economic survival. The family of rich Common Market club members will now help out their poor relation.

For Spain, the second-largest nation in size in Western Europe and the fifth-largest in population, the issue is more complex, almost of a psychological nature, having to do with pride as much as anything else.

Membership in the European Community is seen as the natural consequence of Spain's post-Franco move to become a representative democracy. Significantly, the formal application to join the Common Market was made immediately after free, democratic elections were held in Spain 18 months after the death of Franco.

Spain was denied entry into the European Community during Franco's rule, and acceptance now is viewed as a seal of approval on the democratic process that Spain has undergone in the last decade. Europe is perceived as buttressing democracy in Spain, a system that has been the exception rather than the norm here, and as ensuring that the democratic institutions have arrived to stay.

In Portugal, too, Common Market membership is seen as shoring up democracy.

The Iberian Peninsula's isolation from Europe, however, goes back long before Franco's time. Joining the European Community, officially scheduled for Jan. 1, ends a deep-rooted complex among Spaniards who continue to bristle over the oft-quoted 17th century dictum of France's Cardinal Richelieu: "Africa begins at the Pyrenees."

Agreement in Brussels on expanding community membership amounts to leveling out the massive mountain range that separates Spain from France and to terminating three centuries of isolation.

For the 300 years since the end of the Hapsburg dynasty's rule in Spain, the country was back-to-back with Europe, obscurantist and declining. Real contact with Europe came only when Napoleon invaded the country and then it took Britain's Duke of Wellington to drive the French out.

In recent days, as the Common Market negotiations entered the final lap, commentators have made much of the obviously simplified scenario of three isolated centuries. This century Spain stood on the sidelines of both world wars, was bypassed by the American Marshall Plan and endured 40 years of rule by Francisco Franco, whose government actively cultivated the image of proud isolationism.

Such psychological traits lay close to the surface in a parliamentary debate here Wednesday on the entry issue that also was intended to boost Moran's confidence on the eve of his trip to Brussels for yesterday's last-minute bargaining. The final agreement by community representatives and those of Portugal and Spain came early this morning.

The ethnically proud and separatist-prone Basques and Catalans are not noted for embracing the wider cause of Spain but they, too, in parliament closed ranks and joined the bid to end the breach and belong to the European market.

"Membership of the EC is a mighty challenge the Spanish state faces to break out of isolationism," said the parliamentary spokesman for the Basque nationalists.

In the final preparations for today's agreement, the conservative opposition dropped its line that Spain should not join the Common Market "at any price." Manuel Fraga, the rightist leader in parliament, called for a clear commitment to Europeanism and said Spain was prepared for "the cost of membership."

If isolationism is one theme, the second is the linkage between Europe and democracy. In the background there is the all-important issue of a democratic Spain, in Europe and acting as a fully supportive member of the North Atlantic Treaty Organization.

Spain was denied entry into NATO on political grounds during Franco's rule and it finally became the 16th member of the alliance three years ago.

Prime Minister Felipe Gonzalez, as opposition leader, argued against NATO membership in 1982. One of his first government decisions when he won election later that year was to freeze negotiations with the alliance's military command.

Gonzalez has since come around publicly to NATO membership, but he says he still intends to honor an electoral campaign pledge that the issue of remaining within NATO will be put to a referendum.

European Community membership is seen by western diplomats in Madrid as well as by senior officials in Gonzalez's government as being of key importance in the prime minister's plan to gain endorsement for NATO in a plebiscite scheduled for early next year.

Gonzalez intends to link the alliance, which most Spaniards oppose, with the European Community, which virtually all Spaniards welcome.

But the general enthusiasm over joining the community tends to ignore the economic impact of membership, which is certain to be severe, at least in the short term, both for Spain and for Portugal. Agriculture will benefit -- although not some sectors such as dairy farming -- but industry will take a considerable knock.

Spanish industry has grown in a hothouse of protectionism that has allowed it to become, among other achievements, a major car exporter. But membership in the Common Market means the adoption of a common external tariff which, over a seven-year transition period, will bite deep into Spain's currently comfortable customs shield. Entry also means the introduction of European fiscal measures, notably the value-added tax, which will end the edge enjoyed by Spanish products.

Economists in Madrid estimate that the double effect of common tariffs and European fiscal practices will cut the overall protection enjoyed by Spanish industry by about half. The imposition of other European measures, such as quality controls, will create added costs for Spanish industry and put it still further at the mercy of European Community competitors.

With 2.7 million unemployed in Spain -- more than 21 percent of the working population -- economists are less sanguine than the politicians and the general public over market entry. Spanish workers will not be able to enjoy access to the European job market until the end of the seven-year transition period.

Common Market membership, by contrast, has proved a winner for many non-Spanish business enterprises that took a long term bet on membership and set up manufacturing centers in Spain before it joined the Common Market. The U.S. auto producers Ford and General Motors are now well established in Spain and will gain from added access to European Community markets.

The communications company AT&T is the latest of the major multinationals that have moved into Spain in anticipation of membership.

Gonzalez stressed today that Spanish society now will face major challenges in adapting to the future. Domestic business must be far more competitive to survive. An end to isolation means acquiring a new dynamism, he said.