In this Wed. Dec. 5, 2012, photo, containers are unloaded from cargo ships at the Port of Los Angeles. Most economists agree that the snapshot of U.S. economic growth released Wednesday, Jan. 30, 2012, is going to look dismal. (AP Photo/Nick Ut)

WASHINGTON (AP) -- The U.S. economy shrank from October through December for the first time since the recession ended, hurt by the biggest cut in defense spending in 40 years, fewer exports and sluggish growth in company stockpiles. The decline occurred despite faster growth in consumer spending and business investment.

The Commerce Department said Wednesday that the economy contracted at an annual rate of 0.1 percent in the fourth quarter. That's a sharp slowdown from the 3.1 percent growth rate in the July-September quarter and the first contraction since the second quarter of 2009.

Economists said the surprise decrease in the nation's gross domestic product wasn't as bad as it looked. The weakness was primarily the result of one-time factors. Government spending cuts and slower inventory growth subtracted a total of 2.6 percentage points from growth.

Those volatile categories offset a 2.2 percent increase in consumer spending, up from only 1.6 percent in the previous quarter. And business spending on equipment and software rose after shrinking over the summer.

"Frankly, this is the best-looking contraction in U.S. GDP you'll ever see," Paul Ashworth, an economist at Capital Economics, said in a note to clients. "The drag from defense spending and inventories is a one-off. The rest of the report is all encouraging."

Another positive aspect of the report: For all of 2012, the economy expanded 2.2 percent, better than 2011's growth of 1.8 percent.

Exports fell by the most in nearly four years, likely a result of Europe's recession and slower growth in China and some other large developing countries.

The economy may stay weak at the start of the year because Americans are coming to grips with an increase in Social Security taxes that has left them with less take-home pay.

Subpar growth has held back hiring. The economy has created about 150,000 jobs a month, on average, for the past two years. That's barely enough to reduce the unemployment rate, which has been 7.8 percent for the past two months.

Economists forecast that unemployment stayed at the still-high rate again this month. The government releases the January jobs report Friday.

The slower growth in stockpiles comes after a big jump in the third quarter. Companies frequently cut back on inventories if they anticipate a slowdown in sales. Slower inventory growth means factories likely produced less.

Heavy equipment maker Caterpillar, Inc. said this week that it reduced its inventories by $2 billion in the fourth quarter as global sales declined from a year earlier.

The biggest question going forward is how consumers react to the expiration of a Social Security tax cut. Congress and the White House allowed the temporary tax cut to expire in January, but reached a deal to keep income taxes from rising on most Americans.

The tax increase will lower take home pay this year by about 2 percent. That means a household earning $50,000 a year will have about $1,000 less to spend. A household with two high-paid workers will have up to $4,500 less.

Already, a key measure of consumer confidence plummeted this month after Americans noticed the reduction in their paychecks, the Conference Board reported Tuesday.