US oil settles down 1.3%, at $51.65 a barrel; lowest since April

Where are oil prices headed?

Oil prices closed at their lowest level in nearly three months on Wednesday as data showed an unexpected build in U.S. crude oil and product stocks.

U.S. oil prices closed down 68 cents, or 1.30 percent, at $51.56 a barrel. That was its lowest settlement since April 10.

Read MoreWhy oil could revisit its lows and then some

quickly reversed gains made earlier in the day on expectations of a decline in U.S. inventories and the failure so far of Iranian nuclear talks to produce a deal.

While most expected the U.S. Energy Information Administration's (EIA) weekly report to show a decline in crude oil and gasoline stocks, both rose, along with distillates.

Brent crude was flat to higher around $57.40 a barrel.

"It's negative all around," Gareth Lewis-Davis, commodities strategist with BNP Paribas, said of the EIA report. "It's part of the downward trend that's been going on for two weeks, and it's likely to last for the rest of the day."

The falling oil play

Crude was already facing downward pressure from an accelerating plunge in China's stock market and the Greek debt crisis, both of which raised concern about fuel demand.

Chinese stocks slid after the country's securities regulator warned that investors were in the grip of "panic sentiment" and the market showed signs of freezing up as firms had their shares suspended.

China is the world's second-largest oil consumer.

In the Greek debt crisis, euro zone members have given Athens until the end of the week to come up with a proposal for sweeping reforms in return for loans that would keep the country from crashing out of the single currency.

Read More Oil rout dashes hopes of reprieve for some drillers

"Turmoil in China and Greece may put recent robust demand growth at risk," Morgan Stanley analysts said in a report.

"Investors have justifiable concerns about the outlook for both supply and demand going forward given current events."

Earlier on Wednesday, crude had gleaned some support from dragged-out negotiations in Vienna between Iran and six world powers.

The talks went beyond a self-imposed deadline as officials on both sides talked of important differences preventing a deal to lift sanctions and so allow more Iranian oil onto world markets.

"Those market participants who have been betting on a rapid Iranian return to the oil market are now likely to square their positions, which should lend short-term support to prices," said Carsten Fritsch, senior oil analyst at Commerzbank.