By Chester Tay

Malaysia's trade surplus in July was larger than expected as exports to China and the U.S. rose while imports from Asia dropped.

The country's trade surplus expanded 57% compared with the same period a year earlier to 25.15 billion ringgit ($6.03 billion), Malaysia's Ministry of International Trade and Industry said Friday.

The median forecast from a Wall Street Journal poll of 10 economists was for a trade surplus of MYR15.10 billion. The trade surplus in June was MYR20.89 billion.

Exports in July grew 3.1% from a year earlier, compared with the median forecast for a 1.0% decline and June's 8.8% increase.

The ministry said exports for both manufactured and agricultural goods grew for the second consecutive month. Manufactured goods accounted for 87% of total exports.

Malaysia's exports to China, one of its largest trading partners, expanded 14% in July, the fourth consecutive month it has increased, driven by higher exports of iron and steel products, palm oil and palm oil-based agricultural products.

Exports to the U.S. in July climbed 29%, supported mainly by higher exports of manufactured goods, including electronics and electrical products, rubber products, wood products, petroleum products as well as machinery, equipment and parts.

Compared with the month before, Malaysia's exports grew 12% in July.

Imports in July declined 8.7% from a year earlier, after June's 5.6% fall. The poll of economists had predicted a 4.2% decline.

Total imports were dragged by lower imports of processed industrial supplies, particularly iron and steel. The ministry said imports of capital goods also dropped in July, especially imports of parts of machinery and mechanical appliances.

Write to Chester Tay at chester.tay@wsj.com