Oil prices moved into the red, erasing much of this week’s gains as investors took profits.

Prices had been on the rise earlier Thursday following concerns that Iraqi Kurdistan’s independence vote could hit supply from the oil-rich region and after U.S. data Wednesday showed that record-high exports of U.S. crude and additional demand from refineries helped drain 1.8 million barrels from U.S. crude inventories last week.

But...