The United States ran up a near-record balance-of-payments deficit of $31.8 billion in the second quarter, clearly establishing the country's status as a debtor nation for the first time in 71 years, the government announced yesterday.

The balance-of-payments deficit, the broadest measure of foreign trade in goods, services and investments, jumped 4.9 percent over the first-quarter deficit of $30.3 million, the Commerce Department reported. The current account deficit was the second largest on record, coming in just under the $32.5 billion mark set in the third quarter of 1984.

While most attention has been focused on the rising merchandise trade deficit, expected to reach a record $150 billion this year, the balance of payments is considered a better measure of the country's international economic standing.

What it showed was the United States speeding into foreign debt at a rate that could push it past Brazil, which currently owes more than any other country, about $100 billion, economists said.

The deficit has been of bipartisan concern on Capitol Hill, where Democrats view the worsening trade picture as an opportunity to gain seats in the 1986 elections and Republicans fear it could cost them control of the Senate.

"We have a trade hemorrhage," Rep. Richard Gephardt (D-Mo.) declared. "We are not getting beaten in world trade. We are getting creamed." Gephardt is cosponsoring one of the major trade bills introduced in Congress.

Congressional concern over the merchandise trade deficit, which reached brushfire proportions over the summer, forced President Reagan to take a more aggressive stance on the U.S. trade imbalance. He is expected to unveil his new program in a major speech next week and trade is expected to come up as a major issue in the president's press conference today.

The burgeoning trade deficit, fueled by a flood of imports, has been blamed for the nation's sluggish economic performance, cutting as much as two percentage points off the gross national product. The effects showed up yesterday as the Federal Reserve reported that American industry worked at 80.5 percent of its capacity last month -- essentially unchanged over the past five months and about 5 percent lower than the rate most industries prefer.

Capacity utilization has remained below 81 percent since March, an indication of how low-cost imports have swamped American manufacturers. It is, moreover, below the 81.7 percent average for the past 18 years and far below the 86.9 percent peak in the 1978-1980 period.

In a third economic report released yesterday, inventories remained essentially static in July, indicating that buyers are keeping up with factory production. The inventories increased just 0.02 percent while sales increased 0.9 percent, the Census Bureau reported.

The only bright side of the balance-of-payments report was a doubling of receipts for services such as banking, tourism, engineering and investments -- mainly because of the continued fall in the value of the dollar.

This left the service sector $4.5 billion in the black, an improvement of $2.2 billion over the first-quarter performance, but hardly enough to make a dent in the soaring merchandise trade deficit, which rose $3.5 billion in the second quarter to a record $33 billion.

For years, the service sector has been able to carry larger merchandise trade deficits, but this year's record imbalance is far too high to be offset by the service sector.

Last year's current account deficit was $101.5 billion, while the figure for 1985 is expected to reach $120 billion. It has already reached $62.1 billion in the first six months of the year.

With the heavy debt to foreigners, the United States can no longer look to the inflow of interest payments from America's overseas investments to cover the trade balances. Instead, economists are concerned that U.S. interest payments to overseas investors will make it as hard to bring down the balance-of-payments deficit as it is to lower the merchandise trade deficit.

Commerce Secretary Malcolm Baldrige said in June that it appeared the United States had become a debtor nation for the first time since 1914, and yesterday's figures confirmed that. But the Commerce Department said no official confirmation will be available until the end of the year.