WASHINGTON (Reuters) - The U.S. trade deficit increased to a near 9-1/2-year high in February as both exports and imports rose to record highs, but the shortfall with China narrowed sharply.

Shipping containers are being loaded onto Xin Da Yang Zhou ship from Shanghai, China at Pier J at the Port of Long Beach in Long Beach, California, U.S., April 4, 2018. REUTERS/Bob Riha Jr.

The Commerce Department said on Thursday the trade gap rose 1.6 percent to $57.6 billion. That was the highest level since October 2008 and followed a slightly downwardly revised $56.7 billion shortfall in January.

The deficit has now risen for six straight months. The goods trade deficit was the highest since July 2008 and the surplus on services was the lowest since December 2012.

Economists polled by Reuters had forecast the trade gap widening to $56.8 billion in February from a previously reported $56.6 billion in the prior month.

Part of the rise in the trade deficit in February reflected commodity price increases. The politically sensitive goods trade deficit with China fell 18.6 percent to $29.3 billion. The deficit with Mexico surged 46.6 percent in February.

News of the worsening trade deficit comes as the United States and China are embroiled in tit-for-tat tariffs which have rattled global financial markets.

President Donald Trump’s administration on Tuesday targeted 25 percent tariffs on some 1,300 Chinese industrial technology, transport and medical products, to force changes in Beijing’s intellectual property practices. China swiftly retaliated on Wednesday with a list of similar duties on key American imports including soybeans, planes, cars, beef and chemicals

Trump, who claims the United States is being taken advantage of by its trading partners, has already imposed broad tariffs on imported solar panels and large washing machines. He has also slapped 25 percent import duties on steel and 10 percent on aluminum.

When adjusted for inflation, the trade deficit slipped to $69.11 billion from $69.96 billion in January. The so-called real trade deficit is above the fourth-quarter average of $66.81 billion.

This suggests trade would subtract from first-quarter gross domestic product. Trade sliced 1.16 percentage point from fourth-quarter GDP growth. The economy grew at a 2.9 percent annualized rate during that period.

In February, exports of goods increased 2.3 percent to $137.2 billion, boosted by shipments of industrial materials and supplies as well as sales of motor vehicles and engines. Exports to China were unchanged in February.

Goods imports jumped 1.6 percent to $214.2 billion in February, lifted by imports of food, industrial materials and supplies, and capital goods.

Imports of services rose to a record $47.8 billion from $46.8 billion in January, likely boosted by royalties and broadcast license fees related to the Winter Olympics.

Imports from China declined 14.7 percent in February.