The Commerce Department said exports increased 1.6% to $123.3 billion, while imports declined by 0.6% to $149.3 billion.
Analysts polled by Reuters had expected the trade deficit to widen to $30.2 billion in May. The trade gap in April was revised to $28.8 billion from a previously reported $29.2 billion deficit.
May's import level was the lowest since July 2004 and the 10th straight monthly decline, providing further evidence that the recession-mired United States has diminished as a source of demand for the rest of the world.
The auto sector has been hard hit in the economic slowdown and May imports of automotive vehicles and parts slipped to $10.2 billion, the lowest level since March 1996, while auto exports were the lowest since July 1998.
The monthly deficit on goods trade with China grew to $17.5 billion from $16.8 billion in April and was the largest with any single country.
But the U.S. trade deficit with other big trading partners declined, falling to $2.8 billion with the European Union in May, for the lowest reading since March 1999, and retreating to $1.9 billion with Japan, which was the lowest since February 1984.
Imported oil cost $51.21 a barrel in May, up from $46.60 in April. The value of crude oil imports in May declined only slightly to $13.4 billion, despite a sharper decline in the quantity of oil actually imported, to 262 million barrels from 293 million in April, the Commerce Department said.