President Carter, nearing the end of his week-long trip to Europe, publicly urged Spain today to join the North Atlantic Treaty Organization and the European Common Market.

The president arrived here early this afternoon to begin a visit of less than 24 hours and quickly set out the American position in support of Spain becoming "a full member . . . of the European and Atlantic communities.

Speaking at a lunch hosted by Spain's King Juan Carlos I, Carter said:

"We are pleased that you have begun negotiations for entry into the European Community because we believe that Spain's accession will strengthen the community, just as the community strengthens Europe.

"Similarly," he continued, "we hope that Spain will see its own interests served by participating in the collective defense of the West."

Carter was careful to note that "we fully recognize that this is a decision to be taken solely and exclusively by Spain -- in its own time and in its own way."

Nevertheless, his comments were a public American endorsement on issues involving controversy both here and elsewhere in Western Europe.

Spanish membership in NATO is strongly opposed by the country's Communist and Socialist parties and also entangled in the issue of the status of Gibraltar, the possession of Britain, a NATO member, but considered by Spring to be Spanish soil.

In addition, the admission of Spain and Portugal to the European Common Market, now planned for 1983, has more recently become an issue involving another U.S. ally, France.

French President Valery Giscard d'Estaing earlier this month called for a delay in the admission of Spain and Portugal to the Common Market because of French fears of the economic consequences of cheap agricultural exports from the two countries.

Then last week at the Common Market meeting in Venice, West German Chancellor Helmut Schmidt called for Spain and Portugal to reduce their subsidies to farmers before entering the Common Market.

Carter's careful language on the NATO question was a recognition of the issue's sensitivity here. Leftist parties are demanding that the question be put to a public referendum but this is opped by the government for fear that it would lose.

U.S. officials have said Carter decided to stop here today, and in Lisbon Thursday at the end of his European journey, primarily as a symbolic gesture to the development of democracy in both countries.

"The growth of Spanish democracy has been a tonic for the entire Western world," Carter said at the state luncheon. "Spain refutes the false contention that the sweep of history is invariably toward authoritarianism -- so Spain is a source of hope and and inspiration to democrats everywhere."

Carter also referred to Spain as "a bridge between the Third World and the West" and said Spain provided to other developing countries "a model to follow in shaping their own societies."

Tonight, Carter held talks with Spanish Prime Minister Adolfo Suarez. No details of the talks were made public.

In between these official functions, the president, accompanied by his wife, Rosalynn, and daughter, Amy, toured Madrid's famed Prado Museum where he expressed a preference for the workd of the Spanish master El Greco.

Carter flew here today from Belgrade, where this morning he concluded a 24-hour state visit to Yugoslavia.

At the end of the Yugoslav visit, the two governments issued a joint declaration that expressed "great concern over the serious deterioration in the international situation which represents a threat to world peace" but did not refer to the Soviet Union's invasion of Afghanistan.