Production at the nation's factories, mines and utilities edged up a slight 0.2 percent in June as strength in the nonmanufacturing sector helped offset a big drop in auto production, the government said yesterday.

The Federal Reserve said the production increase followed a much stronger 0.5 percent rise in output during May. In April, production showed no increase at all.

Robert Ortner, undersecretary for economic affairs at the Commerce Department, termed the modest June increase "not very exciting," but he predicted that increasing exports by American manufacturers would boost factory output.

The Reagan administration is pinning hopes for stronger economic growth this year on a turnaround in the country's huge trade deficit brought about by a weaker dollar. The fall in the dollar is expected to make American products once again competitive on world markets.

In a separate report yesterday, the government said that the trade deficit in May swelled to $14.4 billion as a record level of imports offset a healthy gain in exports, which rose to $20.4 billion, the second highest monthly total on record.

While private economists believe American exports will continue to rise, many of them are not as optimistic as the administration that the improvement will be enough to offset widespread weakness in other parts of the economy.

Michael Evans, head of a Washington consulting firm, said he believed overall economic growth as measured by the gross national product fell to an annual rate of 1 percent in the April-June quarter. He said he did not look for any improvement for the rest of the year.

Evans said much of the increased factory production went into a big buildup of unsold inventories, which will have to be worked off in the second half of the year and will thus hold back economic activity.

So far this year, industrial production has expanded at an annual rate of 2.4 percent, far ahead of the 1.0 percent growth in 1986.

In June, manufacturing output remained unchanged following a big 0.4 percent rise in May. It now stands 3.6 percent above where it was a year ago.

The output of durable goods -- items expected to last three or more years -- was unchanged in June, while production of nondurable goods edged up 0.1 percent.

In the durable goods category, production of autos fell 4.8 percent as auto makers continued efforts to trim high inventory levels. Autos were assembled at an annual rate of 6.9 million units in June, down from 7.1 million units in May.

The strength last month came in nonmanufacturing. Output in mining was up 0.7 percent, but even with the rise the category -- which includes oil and gas drilling -- is 1.2 percent below where it was a year ago.

Production at s utilities rose 1.3 percent in June following an even stronger 1.9 percent jump in May.

The manufacturing of defense equipment posted a 0.3 percent gain, continuing a trend this year of moderate increases, while production of business equipment edged down 0.1 percent following a 0.6 percent increase in May. The various changes left the index at 128.2 percent of its 1977 base of 100.

A separate report from the Commerce Department showed that business inventories rose 0.7 percent in May, the biggest increase in more than three years.