The U.S. trade deficit narrowed slightly in December, but the improvement wasn't enough to keep the deficit for the entire year from rising to the highest level since 2012. That should provide fuel for President Donald Trump's contention that America needs a tougher approach to trade.

The deficit in December fell 3.2 percent to $44.2 billion, the Commerce Department reported Tuesday. A gain in exports of commercial aircraft, heavy machinery and autos offset a rise in imports. For the whole year, the deficit rose 0.4 percent to $502.3 billion, the highest annual imbalance since 2012.

Trump has pledged to impose penalty tariffs on countries such as China and Mexico to force them to drop what he contends are unfair trade practices that have cost millions of American jobs.

Since taking office on Jan. 20, Trump has pulled the country out of a 12-nation Pacific trade deal negotiated by former President Barack Obama. He has given notice that he also wants to renegotiate a two-decade-old free trade agreement with Mexico and Canada. Trump has also gotten into a dispute with the president of Mexico over who will pay for a border wall between the two countries. The Trump administration has suggested it might use a 20 percent border tax on goods from Mexico to pay for the wall.

Trump made America's large trade deficits, lost factory jobs and stagnant wages for the middle class a central part of his campaign.

For 2016, America's deficit with China actually declined slightly, dropping 5.5 percent to $347 billion after hitting an all-time high of $367.2 billion in 2015. Even with the improvement last year, the deficit with China is the largest with any country.

The deficit with Mexico rose 4.2 percent in $63.2 billion in 2016, the largest imbalance with that country since 2011.

Trump has contended that both China and Mexico are using unfair trade practices such as currency manipulation to boost their sales to the United States. Private economists contend that broader factors, such as lower wages in both China and Mexico, play a bigger role in determining the trade deficits.

U.S. exporters have struggled for the past two years with a rising value of the dollar, which has made U.S. goods less competitive in global markets while making foreign goods cheaper for U.S. consumers. American manufacturers have also struggled with economic weakness in many key overseas markets.

The $502.3 billion deficit last year was up from a 2015 trade gap of $500.4 billion. For 2016, exports fell by 2.2 percent after a decline of 4.8 percent in 2015 as. Imports were down 1.8 percent last year, reflecting in part the drop in global oil prices.

For 2016, the widening trade deficit shaved 0.1 percentage point from overall growth, down from a bigger 0.6 percentage point reduction in growth in 2015. The economy slowed to growth of just 1.6 percent last year.

Analysts are hoping that growth will rebound to around 2.5 percent in 2017 and even more in 2018, fueled by Trump's stimulus program of tax cuts, deregulation and increased spending on infrastructure. Trump pledged in the campaign to boost economic growth to 4 percent or better.