The U.S. trade deficit climbed slightly to $7.7 billion in May on a surge in oil imports and increased shipments of cars from Canada, but the deficit with Japan, which is far and away the country's largest, dropped by $1 billion.

Although the total deficit in May grew 5.8 percent from April's revised $7.3 billion imbalance, analysts took a generally positive view of the trade numbers.

They pointed to the continued strength of American sales overseas, which at $32.8 billion was the second-highest level on record.

Imports also increased in May, reaching $40.5 billion.

"We can be encouraged by our continued steady export growth of 8 percent this year, which is more than double the overall growth of imports," said Commerce Secretary Robert A. Mosbacher.He noted that the deficit had dropped by $2.3 billion from May 1989 and that the deficit for the first five months of 1990 is almost $6 billion less than for the same period last year.

"Export growth is keeping us out of a recession," said Stephen Cooney, director of international investment for the National Association of Manufacturers. "Manufactured goods exports topped $25 billion for the first time ... and we are looking at a total U.S. export year of about $400 billion. That's a major improvement."

Allen Sinai, chief economist of the Boston Co., called trade "the bright spot of the U.S. economy," and said, "The U.S. economy would not be growing at all" without the strong export push.

He said economic growth in West Germany and Japan, two major trading partners, was pulling in U.S. exports while a slowdown in the domestic economy was holding down the level of imports.

U.S. purchases of foreign-made capital goods -- the machines used in factories, for example -- declined by $300 billion, a reflection of the economic slowdown, while American exports of capital goods increased by $300 billion.

Lawrence Chimerine, an economic consultant from Norristown, Pa., and other economists predicted the deficit would end the year at about $90 billion -- the first time since 1983 that the U.S. imbalance would have dropped below $100 billion -- and a turnaround from earlier forecasts that the deficit would remain at about the 1989 level of $109.4 billion.

Economists said the three major U.S. auto manufacturers were stockpiling cars made in their Canadian factories to prepare for possible labor trouble. Labor negotiations opened this week between the United Auto Workers and the Big Three U.S. car manufacturers.

A 15 percent increase in shipments of foreign oil -- which accounted for half of the jump in imports -- was blamed on a spring heat wave that increased utilities' demand for petroleum.

While the deficit with Japan declined by 25 percent, it still remained the nation's highest at $3 billion.

The 1990 deficit with Japan has dropped by $4.1 billion as Americans bought fewer Japanese products and sold more American-made goods in Japan.

Part of the decline in Japan's trade surplus is due to a shift in the production of cars to factories in the United States.

Imports of Japanese cars dipped in May by $215 million.

Once again, trade with Western Europe was a bright spot for the United States, which posted an $811 million surplus in May and a $3.3 billion improvement for the first five months of the year.

The May figures also showed a $100 million surplus with Mexico compared to a $100 million deficit the month before.