* U.S. crude stocks fall 5.7 mln barrels, refining rates down -EIA
* U.S. gasoline, distillates stock build signals lower demand
* Kirkuk-Ceyhan pipeline oil flow falls to 225,000 bpd -source
* Iraq crisis, U.S.-Iran tensions raise supply concerns
* OPEC leaning toward nine-month extension of supply cut -sources (Updates prices)
NEW YORK, Oct 18 (Reuters) - Brent oil prices retreated from three-week highs on Wednesday, after a surprising drop in U.S. refining rates and an unexpected gasoline and diesel stock build signaled lower demand in the world's top oil consumer.
Brent crude futures were up 19 cents to $58.07 a barrel by 1:37 p.m. EDT (1737 GMT). The global benchmark hits its highest in three weeks earlier in the session at $58.54 a barrel because of ongoing tensions around oil-rich Iraq and Iran, which raised risk premiums.
U.S. West Texas Intermediate (WTI) crude futures were up 15 cents to $52.03 a barrel.
U.S. crude inventories fell 5.7 million barrels last week, the Energy Information Administration said, exceeding analysts' expectations.
U.S. refiners throttled down activity as the autumn maintenance season got underway, and refining rates fell 4.7 percentage points to 84.5 percent of total capacity, the seasonally slowest rate of output since 2011.
However, inventories of gasoline and diesel rose, the latter unexpectedly, reviving some concerns about elevated stockpiles during a time when demand for petroleum products declines.
"A setback in refinery utilization rates occurred as refiners undergo seasonal maintenance," said Anthony Headrick, energy market analyst at CHS Hedging LLC in Inver Grove Heights, Minnesota. "Builds in refined products and a setback in refined product demand provides weight to the energy complex."
The market has been buoyant this week due tensions in the Middle East after northern Iraq threatened to disrupt oil flows through a key pipeline from Iraq to Turkey.
Crude flows through the 600,000 barrel-per-day (bpd) Kurdish pipeline to the Turkish port of Ceyhan have dropped off sharply to around 225,000 bpd, a shipping source told Reuters.
"It remains to be seen whether the Kurds, after withdrawing from the region they claim to be entitled to, will allow crude oil to be transported by pipeline across their territory to the Turkish Mediterranean port of Ceyhan," said analysts at Commerzbank.
The Iraq crisis represents one of two notable Middle Eastern threats to oil supply, along with the ongoing dispute between the U.S. and Iran. U.S. President Donald Trump last week refused to certify Iran's compliance over a nuclear deal, leaving Congress 60 days to decide on further action against Tehran.
During the previous round of sanctions against Iran, some 1 million barrels per day of oil was cut from global markets.
More than one month ahead of OPEC's next official meeting, sources told Reuters its members were leaning toward extending an oil supply cut deal struck with Russia and other producers for a further nine months.
Three OPEC sources said keeping the curbs in place until the end of 2018 was a likely outcome, while a fourth said an extension of six to nine months would be needed to remove all excess oil in storage.
(Additional reporting by Karolin Schaps in Amsterdam and Henning Gloystein in Singapore; Editing by Chris Reese and Marguerita Choy)