Mohammed Barkindo, secretary general of the Organization of Petroleum Exporting Countries (OPEC), speaks during a news conference following the 174th Organization Of Petroleum Exporting Countries (OPEC) meeting in Vienna, Austria, on Friday, June 22, 2018.

Oil prices fell on Thursday after weekly government data showed a surprise rise in U.S. crude stockpiles last week as refineries cut output, while gasoline stocks decreased and distillate fuel inventories rose.

Crude inventories rose by 1.2 million barrels in the week to June 29, the Energy Information Administration said on Thursday, compared with analysts' expectations for a decrease of 3.5 million barrels.

“An unexpected build in the U.S. commercial crude inventory has prompted profit-taking,” said Abhishek Kumar, Senior Energy Analyst at Interfax Energy in London.

U.S. West Texas Intermediate (WTI) crude futures ended Thursday's session down $1.20, or 1.6 percent, at $72.94. Brent crude futures fell 79 cents, or 1 percent, to $77.45 per barrel by 2:27 p.m. ET.

Oil earlier traded near its highest in 3-½ years on Thursday, boosted by potential disruptions to flows from Iran and the Middle East despite a fresh demand from U.S. President Donald Trump that OPEC cut prices.

@realDonaldTrump: The OPEC Monopoly must remember that gas prices are up & they are doing little to help. If anything, they are driving prices higher as the United States defends many of their members for very little $’s. This must be a two way street. REDUCE PRICING NOW

Trump again on Wednesday accused the Organization of the Petroleum Exporting Countries of driving up fuel prices.

"The OPEC Monopoly must remember that gas prices are up & they are doing little to help," Trump wrote on his personal Twitter account. "If anything, they are driving prices higher as the United States defends many of their members for very little $'s.This must be a two way street. REDUCE PRICING NOW!"

OPEC together with a group of non-OPEC producers led by Russia started to withhold output in 2017 to prop up the market.

"If Trump continues to believe that OPEC are not doing enough, we would not rule out an SPR (Strategic Petroleum Reserve) release from the U.S., or possibly even export restrictions on petroleum products," ING said in a note.

"However with plenty of uncertainty over Iranian supply, and the Syncrude outage in Canada, the market is likely to remain fairly well supported in the near term."

Recent price rises have also been spurred by a U.S. announcement that it plans to reintroduce sanctions against Iran from November, targeting oil exports.