Oil advanced the most in three weeks in New York after U.S. crude stockpiles unexpectedly decreased as production and imports declined.

Inventories fell 4.2 million barrels last week, Energy Information Administration data show. An 850,000-barrel gain was forecast by analysts surveyed by Bloomberg before the report. Crude production declined to a two-month low. Imports of both crude and fuels slipped in the week ended July 24.

Crude in both New York and London entered a bear market in the past week on signs the global surplus will be prolonged as Iran bids to restore output after its nuclear accord. Leading members of OPEC are pumping oil at record levels. Concern that turmoil in China’s stock market will reduce demand in the country has weighed on commodities.

West Texas Intermediate for September delivery rose 81 cents, or 1.7 percent, to settle at $48.79 a barrel the New York Mercantile Exchange. It was the biggest gain since July 9. Prices are in a bear market after having lost more than 20 percent from their closing peak this year on June 10.

Source: Bloomberg