The U.S. foreign trade deficit narrowed to $1.9 billion in June even though the nation spent more to import oil than in any month since March 1977, the Commerce Department reported yesterday.

Both exports and imports hit record levels last month, the report indicated.

Exports of $15 billion were 8.5 percent ahead of the May figure, and imports of $16.9 billion in June were up 3.6 percent from the previous month.

June's $1.9 billion deficit was a marked improvement from May, when imports exceeded exports by $2.5 billion. The April deficit had been $2.2 billion.

Still, oil import figures worsened.

The cost of importing oil in June rose 11.5 percent to $4.3 billion. Commerce officials said. This was prior to the Organization of Petroleum Exporting Countries' most recent price increase, effective July 1.

June's dollar total for imported oil was the highest since March 1977, when the nation paid $4.6 billion to import 340.4 million barrels, Commerce figures show.

The volume of petroleum imports increased 3 percent from May to June's 241.4 million barrels. The May figure had been the lowest for any month in 1979, and appeared to reflect the world shortage of crude oil at the time.

The June petroleum import total works out to about 8 million barrels a day - 200 million below President Carter's newly announced "quota" of 8.2 million barrels daily. The quota is part of Carter's program to cut U.S. dependence on foreign oil.

"The overall trade figures are really a little better than they look on face," said Commerce Department analyst Adren Cooper. "If there had been no increase in (the importation) of foreign autos and oil, there would have been no increase in imports."

The six-month deficit of $11.7 billion was nearly one-third lower than last year's six-month deficit of $17.2 billion. CAPTION: Graph, UNITED STATES BALANCE OF TRADE, The Washington Post