The U.S. trade deficit shrank dramatically to $9.7 billion in March - a drop of more than $4 billion - as American producers sold a record amount of goods overseas, the government reported Tuesday.

The Commerce Department said that American exports shot up 23 percent to an all-time high of $28.97 billion while imports were up 3.6 percent to $38.72 billion. The trade deficit is the difference between the two.The March deficit was the lowest monthly imbalance since March 1985 and represented a 29.5 percent improvement from the February deficit of $13.83 billion.

The March improvement was a major surprise and sent the dollar soaring on foreign exchange markets. In European trading, the dollar climbed against the British pound and the Japanese yen.

"Everyone is breathing a tremendous sigh of relief. This is the breath of fresh air we have been waiting for," said Jay Goldinger, an analyst with Capital Insight, a Los Angeles investment firm.

Goldinger predicted that the trade improvement would strengthen President Reagan's position and make it more difficult for Congress to override his promised veto of the omnibus trade bill.

Indeed, the White House seized upon the report as new support for the veto.

"We have said for some time that there is no good time for bad trade legislation, but today's report demonstrates that this is the worst time," spokesman Marlin Fitzwater said. "This is no time to shoot ourselves in the foot and . . . stymie job creation."

In a statement, Commerce Secretary C. William Verity called the report evidence of the "decisive improvement in the trade balance that is now under way."

In a second report Tuesday, the Federal Reserve said that American industry operated at 82.7 percent of capacity in April, up 0.3 percentage point from March. It was the highest operating level in more than eight years and was further evidence, analysts said, that American manufacturers are benefiting from the boom in export sales.

All the good news was in sharp contrast to the jolt financial markets received a month ago when the February trade report was issued. The unexpected widening of the deficit had sent the dollar reeling and pushed the Dow Jones average down by 101 points, its fifth-worst loss ever.

The monthly trade deficit has become the most closely watched barometer of U.S. economic health.

A narrowing of the deficit is seen as a sign of strength for the American economy because it means more jobs in the manufacturing sector.

Additionally, smaller deficits usually translate into less downward pressure on the foreign exchange value of the dollar, which is also important for the country since sharp declines in the dollar can send stock and bond markets tumbling because of investor fears that inflation will rise.

The $28.97 billion in exports sold represented a $5.4 billion increase from the February level, reflecting gains in sales of U.S. machinery, computers, aircraft, chemicals and telecommunications equipment. In addition, $600 million of the increase came in gold sales to Taiwan.