China and the United States have reached agreement on a package of military sales intended to help modernize the destroyers in the Chinese fleet and on a port call by three American destroyers to Shanghai in April, administration officials said yesterday.

Chinese naval officials, who completed a six-week visit to Washington and military sites around the country last month, agreed to buy sonars, torpedoes, gas turbine engines and a sophisticated shipboard gatling gun intended to shoot down antiship missiles, the officials said.

The Chinese would like to be licensed to manufacture the torpedoes, but would buy much of the other equipment outright, one administration specialist said. It was not immediately known how many destroyers would be involved in the naval modernization program. But if all aspects of the agreement reach fruition, sales could total several hundred millions of dollars.

The sales would represent the most significant military transaction so far with China since Defense Secretary Caspar W. Weinberger cleared the way for weapons sales during his visit to Peking in September l983. Officials cautioned that the Chinese, who have expressed interest in certain sales and then backed off in the past, have not yet signed any contracts.

The officials said that in mid- to late April, the U.S. Navy plans to pay its first port call to China since the Communist revolution in 1949. Final details are now being arranged for the projected visit to Shanghai, which will consist of three U.S. destroyers with an admiral on board, the officials said.

Both the modernization deal and the port visit reflect a U.S. desire to cooperate more closely with the Chinese military and help it modernize to cope with what both nations see as a Soviet threat. The Chinese have repeatedly expressed interest in modernizing their military, but have said they must move slowly because of a shortage of funds. They have given economic development the highest priority.

But military modernization was given added emphasis following Vietnam's stiff resistance to the Chinese invasion of l979. The Chinese desire to protect their offshore oil interests is believed to be an additional reason for naval modernization. And according to an article published last summer in the China Business Review, an American publication on trade issues, one of the most important factors pushing the Navy into the forefront is China's emphasis on coastal and offshore economic development. Once in motion, the article said, it was obvious that a stronger Navy was needed to protect that "more trade-oriented" system.

Administration officials say that the Soviet Union's Far Eastern forces have been steadily expanding, with a considerable number of Vietnam-based Soviet Bear and Badger aircraft capable of ranging widely and interdicting sea lanes throughout Southeast Asia. An official said that the Soviets recently moved a new floating drydock to Vietnam's Cam Ranh Bay to add to the already sizable port and airfield facilities there.

The Chinese Navy's concerns extend in particular to the contested Spratly Islands in the South China Sea. Vietnamese troops occupying eight of those islands were reported last year to have increased their combat capabilities. Last May, U.S. intelligence detected a major movement of Chinese ships out of Canton in the direction of the Spratlys, a movement that, according to one report, triggered a move in the same direction by Soviet naval vessels from Cam Ranh.

Officials in Washington said, meanwhile, that Melvyn R. Paisley, assistant secretary of the Navy for research, engineering and systems, will visit China later this month to fill in details on the U.S.-China destroyer modernization package. Paisley is to be accompanied by Steven A. White, chief of naval materiel, and other officials.

Gen. John W. Vessey Jr., chairman of the U.S. Joint Chiefs of Staff, was to arrive in Peking today for the first such visit to China of such a high-ranking military man in nearly four decades. Later this year, both the chief of U.S. naval operations, Adm. James D. Watkins, and Marine Commandant Gen. Paul X. Kelley are to visit China.

The Chinese naval delegation that visited the United States at the end of last year boarded several U.S. Navy vessels and inspected some of the factories where the equipment they intend to buy is made. They visited the General Electric factory in Ohio, for instance, where the LM2500 gas turbine engine is produced.

The destroyers that will visit Shanghai in the spring were chosen in part because they use that same engine.

The Chinese also have agreed to purchase modern towed sonars, Mark 46 torpedoes and the Phalanx close-in weapon system, a rapid-firing gun that the Navy has used to shoot down French-made Exocet missiles in sea trials. The Phalanx, which is manufactured by General Dynamics, caused the most controversy within the government because of concerns about reaction from the Chinese Nationalist government on Taiwan.

The sonars, by comparison, caused little concern, because Taiwan has no submarines, officials said.

The Chinese expressed interest in buying longer-range naval weapons as well, officials said, including the Standard and Sparrow missiles and the radars that go with them. But those more capable weapons have not yet been approved for sale.

In general, the Chinese are interested in learning to produce almost any equipment they buy, Chinese officials said. But U.S. officials said that, with the possible exception of the torpedoes, they do not currently have the technological know-how to make much of the equipment that will be used to modernize their destroyer fleet.

The Chinese will insist, however, that the installation and refitting be done in Chinese ports.

"It is in our interest that the Chinese be able to defend their waters," said an administration official in Washington. "They don't have the kind of Navy that is a threat to American interests there."

One official asserted that U.S. and Chinese naval officials arrived at a "remarkable confluence of views" in the course of Navy Secretary John F. Lehman Jr.'s visit to China last August.