The trade deficit (search) narrowed unexpectedly in May to $55.3 billion as exports rose slightly to a new record and imports retreated a bit from the record set in April, a U.S. government report showed on Wednesday.

The monthly trade gap narrowed about 2.7 percent from April according to the Commerce Department (search) report, defying the median estimate of analysts surveyed before the report who expected it to remain mostly unchanged at about $57.0 billion.

While the deficit was still within sight of the $60.1 billion record set in February, the unexpected narrowing in May could boost the value of the dollar in trading against other currencies.

The dollar was under pressure against the euro earlier this week after China released its own trade figures for June, showing a wider-than-expected trade surplus. That fueled last minute speculation the U.S. trade gap for May could be wider than expected.

The trade deficit with China, a hot-button issue in the U.S. Congress, swelled 7.1 percent in May to$15.8 billion.

Exports in several key categories — such as food, feed and beverages, consumer goods and industrial supplies and materials — rose slightly to new record levels. U.S. exports of services also set a record, as did imports in that category.

Overall exports totaled a record $106.9 billion, up slightly from a revised estimate for April. It was the sixth consecutive month that U.S. exports have been above $100 billion since first passing that threshold in December.

U.S. imports remained near record levels at $162.2 billion, down less than 1 percent from the previous month.

Imports from members of the Organization of Petroleum Exporting Countries (search) were a record $9.8 billion. Average prices for imported oil were the second highest on record in May at $43.08 per barrel, down from a record $44.76 in April.

Imports from Germany and the entire European Union also set records in May, while imports from Mexico were the second highest on record.

Despite the unexpected narrowing in May, the annual trade deficit remained on track to exceed last year's record of $617.6 billion.