Secretary of State George P. Shultz sought today to dispel fears among Spaniards that the United States would pressure Madrid's new Socialist government to remain in NATO, but he added that membership in the alliance would be an advantage both to the West and to Spain.

Speaking at a press conference here before leaving for London on the last leg of his European tour, Shultz said continued NATO membership was "a decision for Spain to make."

Adding that "the U.S. thinks that it would be good for Spain to join the alliance and we think it would be good for the alliance to have Spain as a member," Shultz said the question was "an open one" and that Washington would "await their the Spanish decision."

The secretary also announced that Prime Minister Felipe Gonzalez, whose Socialist Party had a landslide triumph in the national elections in October, had accepted an invitation to pay an official visit to Washington next June.

The low-key approach to the NATO issue was welcomed by Spanish officials. "Shultz didn't try to push us," said a Foreign Ministry source. "We explained we were rethinking NATO, that we needed time and asked him to be patient. He seemed to understand this."

The 24-hour Madrid stopover had promised a potentially delicate round of talks on account of NATO and also because of a bilateral U.S.-Spanish defense agreement, which is awaiting ratification by the Spanish parliament.

But Shultz smoothed out possible misgivings on the Spanish side by implicitly endorsing the new Madrid administration. He said he had been asked by President Reagan "to express the support of the U.S. for the democratic values that were so evident in the last Spanish election."

Shultz also was able to announce progress on the bilateral question. He said he foresaw "no major impediments for a fairly prompt ratification by Spain of the agreement."

The Socialist objection to the defense agreement, signed by the previous administration last June at the same time that Spain joined the Western alliance, is its close linkage to NATO. The Spanish government argues that ratification now would prejudge the NATO issue.

Shultz said this objection could be taken care of in negotiations and that "we should be able to proceed in a satisfactory manner." The secretary's belief that there were no major impediments was, he said, shared by "the officials of the Spanish government with whom I talked."

Spanish diplomatic sources said that the bilateral agreement, which governs U.S. facilities at four bases, could become operative well before its technical expiration date next May.