The United States in June turned in its best monthly trade performance in seven years, the government reported yesterday.

But the good news of a 35 percent drop in the trade deficit for June was tempered by the knowledge that skyrocketing oil prices over the past two months were expected to worsen the trade numbers by the end of the year.

The $5.1 billion deficit for June resulted from a combination of record overseas sales by American companies and a decrease in U.S. purchases of foreign goods, including oil.

Since June, however, oil imports have increased and the price of oil has doubled, largely because of the crisis in the Persian Gulf.

Analysts predicted that the run-up would increase the U.S. trade deficit for two reasons: The value of imports would swell to reflect the higher price of oil, and exports could be expected to decline as higher oil prices and tighter supplies begin to dampen economic growth in Europe and Asia.

"Everybody knows the trade deficit is going to get a lot worse because of the oil prices," said Michael Drury, senior domestic economist for the Boston Co. investment firm.

The United States imported 8.4 million barrels of oil a day in June at an average price of $14.64 a barrel, a decrease both in volume and price from the month before.

In July, however, the American Petroleum Institute reported oil imports increased to slightly less than 9 million barrels a day. With an embargo on sales of Iraqi and Kuwaiti oil, the price of oil had reached $28.40 a barrel on spot markets yesterday -- almost twice what it was in June.

"We're talking about a $50 billion swing in the trade deficit just because of the change in petroleum prices," said Barry Rogstad, president of the American Business Conference.

The June trade numbers, taken separately, were remarkable for the powerful performance put in by American exporters, who sold a record $34.3 billion in goods during the month. At the same time, imports declined $1.2 billion to $39.4 billion, caused largely by continued sluggishness in the U.S. economy.

"It's a great set of numbers," Rogstad said. "Some of the fundamental numbers are going in the right direction."

"The strong positive trend indicates increasing U.S. export competitiveness in the world marketplace," Commerce Secretary Robert A. Mosbacher said.

The trade deficit with Japan, America's largest, dropped by $900 million in June after a $1 billion decline the month before.

For the first six months of the year, the trade deficit with Japan has fallen nearly $5 billion -- "the first really significant fall in our deficit with Japan," said Stephen Cooney, an economist at the National Association of Manufacturers. Even so, the deficit with Japan totaled a substantial $19.6 billion for the first six months of the year.

U.S. trade with Western Europe is running at a $4.3 billion surplus for the first half of 1990, compared with an anemic $7.4 million surplus during the same period last year.

Mosbacher said that the $45.8 billion trade deficit for the first six months of the year was the lowest since the second half of 1983. On an annual basis, this would put the 1990 trade deficit at about $91 billion, a decline of $18 billion from last year's $109.4 billion imbalance.

Cooney hailed the growth in exports, which increased 8.4 percent in the first half of the year while imports rose 2.8 percent. June's export growth included $500 million in sales of airplanes as well as significant sales gains for other manufactured products.

"We are talking about the improved export performance translating into real trade performance gains. But all that is dependent on strong economic growth abroad," Cooney said.

U.S. companies were making a strong showing in overseas sales of consumer goods, especially furniture, small appliances and carpeting -- "things we haven't been competitive in in years," said Drury, of the Boston Co. The difference, he said, is the fall of the value of the U.S. dollar in Europe, which makes American products less expensive there.

Because of the impact on rising oil prices, Mosbacher said yesterday that the government will begin later this year to analyze oil and non-oil trade separately.

"This will provide a better indication of the underlying trend in our international competitiveness," he said.