The U.S. trade deficit shrank for the fourth straight month in August, falling to the lowest level since January as exports rose to an all-time high.

The Commerce Department says the deficit dropped 0.5 percent in August to $40.1 billion, compared to a revised $40.3 billion in July.

Exports increased 0.2 percent to a record $198.5 billion, aided by increased sales of petroleum, telecommunications equipment and industrial engines. Imports also rose by a smaller 0.1 percent to $238.6 billion.

Even with the falling deficit the past four months, the imbalance so far this year is running 4.2 percent higher than the same period in 2013. A larger deficit acts as a drag on the economy because it means more money going to foreign companies.