China recorded a rare trade deficit over the past three months on the back of domestic economic strength and rising global commodity prices, the customs administration said on Sunday.

From January to March, China imported $1.02 billion more than it exported, marking its first quarterly trade deficit since 2004, the General Administration of Customs said.

The trade numbers showed that China's economy was evolving in a more sustainable direction, with it less reliant on exports and a bigger source of growth for the rest of the world, said Isaac Meng, economist with BNP Paribas in Beijing.

Even though the exchange rate is only slowly appreciating, strong inflation, especially labor costs, is making the rebalancing happen, and also domestic demand is so strong, Meng said.

In March alone, China reported a tiny trade surplus of $140 million, following a $7.3 billion deficit in February.

China's exports in March were up 35.8 percent from a year earlier to $152.2 billion. But imports also surged 27.3 percent from a year earlier to a record size of $152.1 billion.

Rising prices helped to drive Chinese imports. For instance, average imported prices of iron ore, a key input for Chinese steelmakers, jumped 59.5 percent in the first quarter from a year earlier, the customs administration said.

Meng said China's export momentum may wane.

People are still trying to assess the impact of Japan, so it's not easy to say whether this pace can be maintained. It is likely to slow down much more in the second quarter, he said.

Economists had expected exports to rise 21.0 percent year on year and imports to increase 19.5 percent year on year, resulting in a trade deficit of $4.2 billion.

(Reporting by Zhou Xin and Simon Rabinovitch; Editing by Chen Aizhu)