Spain's visiting foreign minister said yesterday that his country wants a new military relationship with the United States and the Western alliance, along with American arms, that would give the Spanish military an international role and help keep it out of domestic politics.

Jose Pedro Perez-Llorca said his country desires and is ready for a larger role and voice in Western defense, including eventual membership in the North Atlantic Treaty Organization. At the same time, his government hopes to persuade the United States of the advantages of equipping the Spanish military, both to make it a viable defense partner and to help consolidate civilian democracy at home.

"We've got to help those armed forces to find a role which they haven't had since the 19th century," Perez-Llorca said during a breakfast meeting at The Washington Post. "We are not looking for wars," he said, "but we have to change the pattern of an Army that had a colonial and internal role" through much of Spanish history "and never really had an [external] defense role."

In February, a small, rebellious group of military officers and guardsmen in Madrid attempted to topple the parliamentary democracy that has grown up in Spain under King Juan Carlos in the five years since the end of Francisco Franco's dictatorship. Although the coup failed, it revived concerns about the military and contributed to the view among many Spanish civilian leaders that the military needs to be broadened in its outlook and made less isolated through involvement in NATO.

Presumably, the supply of U.S. arms would also keep the military more contented as its fighting power against external foes becomes more effective.

Perez-Llorca said neither the government nor the vast majority of the Army and the public in Spain wants an internal role for the military. The foreign minister, under questioning, said there were two key elements to modernizing the military.

One was the psychological boost that would come, in time, with a specific responsibility and role in NATO. Spain is seeking entry into NATO within two years and other sources say the Madrid government is expected to submit this proposal for membership to its own parliament for approval this fall. Spanish officials have said they are confident a majority will support the plan to join NATO.

The other element is a need to turn Spain's 350,000-man armed forces into something other than "paper regiments with paper weapons. We have a great manpower capacity. We can equip a big Army," Perez-Llorca said, "and it is good investment for the West to help in this effort."

Perez-Llorca was in Washington for meetings yesterday with Secretary of State Alexander M. Haig Jr. He also met with the U.S.-Spanish Council, where bilateral relations are discussed, such as the renewal of U.S. military base rights in Spain. On Tuesday, Perez-Llorca met briefly with Defense Secretary Caspar W. Weinberger.

The United States has access to two major air bases in Spain and the big port at Rota for missile-firing submarines. The current five-year agreement expires Sept. 21. While officials on both sides are optimistic that a new agreement will be reached, although possibly not by the expiration date, Perez-Llorca said, "We feel the defense relationship with the U.S. is different now."

In the past, he said, the United States tended to view Spain from a military standpoint as mostly a "piece of territory . . . like a big aircraft carrier," where rear-area facilities could be situated. But those attitudes must be forgotten, he said. Spain's forces should have an assigned task in Western defense and "now we want an active role with our own voice, a solid one, so the relationship should be more intense."

U.S. officials said it was clear that Spain wanted some new elements in an eventual basing agreement so it will reflect the stance of the democratic government and not look like an extension of previous agreements reached under the authoritarian Franco Regime.

Perez-Llorca acknowledge that Spain had a "shopping list" of military equipment it wants from the Pentagon. He said Madrid expected credits to buy weapons and also hoped to receive surplus equipment on a loan basis, with the right to purchase, Spain's own military budget, he said, was increasing in real terms by about 25 percent annually, in what he called a "tremendous effort."

The foreign minister said his government viewed the Soviet military potential against NATO's central front and terrorism as the principle challenges to European stability. "That is why," he said, "we have very clear ideas on which side we have to take."

Spanish diplomats have also let it be known that 10 Soviet citizens, including two diplomats, have been expelled from Spain this year for alleged interference in internal affairs and that the government wants to end use of the Spanish-owned Canary Islands in a base for a Soviet fishing fleet in the Atlantic.

Although much of Madrid's bilateral dealings with the United States are in he defense field, Perez-Llorca said that whatever actual problems the Madrid government was having with the Reagan administration thus far were in the economic field, particularly the "hindrance" of some imports from Spain, such as shoes. He said the biggest trade deficit Spain has it with the United States, exceeding even that with oil-exporting countries.