Saudi Arabia has signed a five-year military cooperation agreement with Brazil, the developing world's largest arms exporter, that will enable Riyadh to vastly expand its own small weapons industry and transfer arms to third parties.

Prince Sultan, Saudi Arabia's defense minister, also opened negotiations on a major arms purchase. Officials refused to put a price tag on the deal or give details of the weapons included in it, but they acknowledged it would be the largest arms sale ever made by Brazil.

Already the world's fifth-largest arms exporter, with sales of $2 billion last year, Brazil is aggressively competing with France and Britain in a drive for oil and dollars to aid its struggling economy. Earlier this year, Brazil sold Iraq armored vehicles and rocket launchers in what was estimated to be a $400 million package.

Saudi Arabia buys most of its arms from the United States but has always had a policy of diversifying its sources of weapons. In the past, however, it has bought from France and Britain.

One of the attractions of Brazil appears to be its liberal approach to arms sales. Its quasi-private weapons industry refuses to sell only to Brazil is eager to sell arms to the Saudis because of its $1.2 billion trade deficit with the oil state. Cuba and South Africa. Saudi Arabia will be permitted, on a case-by-case basis, to resell or transfer the weapons it purchases from Brazilunder the terms of the military cooperation agreement signed in Brasilia on Tuesday. The Saudis previously have bought weapons for Iraq and Egypt and they are also the major financial backer of the Palestine Liberation Organization.

The agreement provides for the technical training of Saudi workers in weapons assembly and manufacturing and the transfer of technology. The Saudis long have wanted to expand their fledgling armaments industry, which now is mostly limited to the manufacture of infantry rifles and small-caliber ammunition. The United States and Western European arms manufacturers generally have been reluctant to enter into the kind of joint production agreements the Saudis made with Brazil.

During his three-day official visit, Sultan toured arms factories near Sao Paulo to look at rocket launchers, light armored cars, amphibious vehicles, main battle tanks, aircraft and munitions.

According to officials here, the weapons Saudi Arabia is likely to manufacture jointly with Brazil include the Astros II multiple rocket launcher, which has a range of about 40 miles, the Osorio heavy tank and Tucano trainer planes. Senior Brazilian officials are to go to Saudi Arabia this weekend to test the new tank in the desert.

Brazil's Air Force Minister Delio Jardim de Mattos said the Saudis had also indicated an interest in the AMX subsonic jet fighter that Brazil is developing jointly with Italy for sale in 1987. Saudi Arabia also appears to have plans to buy frigates made by Brazil under license from Britain's Vosper Thorneycroft.

Under the cooperation agreement, the Saudis are expected to help finance the development of a new Brazilian-designed ship-to-ship missile system, which could eventually emerge as a competitor to the France's Exocet.

Such cooperation would undoubtedly put an end to Israel's hopes of selling Brazil its Gabriel ship missile under an agreement that would have curbed Brazil's future sales to Arab clients.

Brazil's weapons already are used by many Arab armies. Weapons sold to Iraq have been financed by the Saudis. A recent agreement for Egypt to assemble 120 Tucano T27 military trainer planes was also made possible with $180 million from Saudi coffers.

Brazil, whose oil imports caused a $1.2 billion trade deficit with Saudi Arabia last year, is eager to balance trade.

"From the political point of view, it's much more logical to deal with the Saudis than with Libya, which is indirectly sending arms to Iran, at the same time as Iraq is our priority client," said Roberto Pereira, editor of the magazine Defense and Technology.

Earlier this year, when Secretary of State George P. Shultz visited Brasilia to initial a military-industrial cooperation agreement, U.S. officials indicated they hoped Brazil would reduce the amount of arms it sells to Libya.

But Brazil is not abandoning Libya, an old client. Brazilian Navy Minister Alfredo Karam is currently in Tripoli with an offer to refit Libya's fleet.

Tough salesmanship by Brazil's 15-year-old national aircraft corporation Embraer, and the considerable sales potential of the propeller-driven Tucano trainer plane, which can carry a formidable array of weaponry for attacking guerrillas on the ground, have awakened the aggressive instincts of its larger competitors.

"Brazilian production of military equipment cannot be quoted against world output -- we are too small for the world to feel," said Embraer's president, Ozires Silva, in an interview. "We are just a seed, and it's easier to destroy a seed than a tree. It's not easy to identify the source of this, but people are trying to stop us."

Brazil's decision in June to sell Honduras eight planes stirred domestic and regional opposition among critics concerned that they could be deployed against Nicaragua's Sandinistas, and thus compromise Brazil's diplomatic efforts in the Contadora group aimed at a peaceful solution to Central America's troubles.