Soviet Foreign Minister Andrei Gromyko warned today that the possibility of a nuclear war is "no exaggeration" if the arms race is allowed "to erupt in space."

Gromyko accompanied his warning against President Reagan's antimissile space project with an apparent olive branch. "Once 'Star Wars' projects are abandoned," he said, "the possibilities will be open for a reduction, even a drastic reduction, of strategic weapons and medium-range nuclear arms."

The Soviet foreign minister spoke at a reception given in his honor by his Spanish counterpart, Fernando Moran, on the second day of an official visit to Spain. The tough speech was aimed at striking an urgent note in Moscow's propaganda battle over Reagan's proposed antimissile research program before arms talks in Geneva later this month.

Gromyko said the Soviet Union's response to the plans was firm and uncompromising: "Attempts to achieve military superiority will not be allowed to materialize either on earth or in the cosmos." While not mentioning the United States directly, Gromyko ridiculed what he termed "attempts to convince public opinion that the path to disarmament lies in the creation of increasingly sophisticated new types of weapons."

Gromyko's attacks on "Star Wars" has been a recurring theme of his trip to Spain and of his talks with Italian leaders during a stay in Rome earlier this week.

The Soviet foreign minister said that his talks in Madrid had centered on "how to prevent the militarization of space and how to contain the arms race, above all the nuclear race, and to forswear a new war." Gromyko's pitch has prompted some support in Italy, where Prime Minister Bettino Craxi has been quoted as urging the United States to give Moscow guarantees on the proposed missile-defense system to aid the negotiating process in Geneva.

There was little immediate evidence, however, that the Soviet foreign minister had succeeded in eliciting similar comments from Spanish leaders.

Gromyko had lunch with Prime Minister Felipe Gonzalez yesterday and then held a round of talks with Foreign Minister Moran. He held further talks today with Moran on what Spanish officials termed wide-ranging international issues and also spent an hour in a protocol audience with King Juan Carlos, the head of state. The veteran Soviet minister returns to Moscow Saturday.

On Gromyko's arrival, Moran said Spain was still reviewing the "Star Wars" debate and had no intention of taking a stand on the issue for the time being. Spanish officials added that in any case Spain would avoid any statements on the space project that could be construed as being linked to Gromyko's visit.

Gromyko apparently also failed to drive any wedges between Spain and the West during his visit. There had been speculation that he might seek to exploit mixed feelings in Spain over continued membership in the North Atlantic Treaty Organization and to fuel antialliance lobbying before a referendum on the NATO issue that Gonzalez has said will be staged early next year.

Spanish officials said that the Soviet minister had refrained from such interference in internal Spanish affairs. In his speech, Gromyko restricted himself to praising Spain's policy against the deployment of nuclear weapons on Spanish soil.

Moran, in his address at today's lunch, said that "for obvious reasons" Spain forms part of the West and "defends its values and way of life." Gonzalez said after his lunch with the Soviet minister that the NATO issue had not been raised. Gonzalez, who spoke with reporters traveling with him to Montevideo, Uruguay, for the swearing in of Julio Sanguinetti as president, plans to meet there with Secretary of State George P. Shultz in what was seen as a counterbalance to the talks with Gromyko.

Gromyko's visit afforded other indicators of the growing western alignment of Spain under Gonzalez's moderate Socialist administration.

On the eve of Gromyko's visit, the Spanish government said that it would begin negotiations with the United States and NATO to establish regulations that would prevent sensitive western technology from being reexported from Spain to the Soviet Bloc.

During the visit, Spanish diplomatic sources said that Madrid had resisted requests by the Soviets that they be allowed to open more consulates in Spain and that the military mission at the Soviet Embassy be enlarged.