U.S. oil prices closed at their lowest in more than six years on Wednesday after U.S. data showed an unexpected rise in crude stockpiles.

U.S. crude stocks were up 2.6 million barrels at 456.21 million barrels last week, the U.S. Energy Information Association said. Stocks at Cushing, Oklahoma, the delivery point for U.S. crude futures, rose 326,000 barrels to 57.44 million.

U.S. crude oil futures, also known as West Texas Intermediate (WTI), settled down 4.3 percent, at $40.80 a barrel. That was the contract's lowest close since March 2009. The front month, September, U.S. contract expires on Thursday.

was down 20 cents, at $46.90 a barrel.

This was in sharp contrast to a Reuters poll, which forecast a 777,000-barrel inventory decrease.

"The numbers were a total surprise, with crude showing a build when the whole (market) was forecasting a draw," Tariq Zahir, managing member at Tyche Capital Advisors in Laurel Hollow in New York, said.

"We feel these numbers are not factored in to the current price of spot crude."

U.S. production, which declined slightly two weeks ago, remains steady in week of Aug. 14 at 9.348 million barrels a day, versus 9.395 million barrels the week earlier.

Bearish sentiment was exacerbated last week when repairs at a large refinery in Whiting, Indiana, caused a large stock build at Cushing.

Oil has lost about a third of its value since June and prices have been hovering just above six-year lows for the past week. The downward trend has been driven by global oversupply and record stockpile levels, analysts say.