U.S. stocks swung between gains and losses Thursday and wound up with a muddled finish as the price of oil plunged. Investors also sold utility and phone company stocks, which have been favored all year, especially after Britain’s vote to leave the European Union last month.

ON WALL STREET. The Dow Jones industrial average fell 22.7 points, about 0.1 percent, to 17,895.9. The Standard & Poor’s 500 index slid 1.8 points, about 0.1 percent, to 2,097.9. The Nasdaq composite rose 17.7 points, about 0.4 percent, to 4,876.8. The Dow rose as much as 66 points in the morning and fell as much as 102 points in the afternoon.

advertisement | advertise on newsday

OIL PRICES. The price of oil fell after the Energy Information Administration said crude oil inventories shrank by 2.2 million barrels last week. Analysts expected a bigger drop of 2.6 million barrels, according to S&P Global Platts. Inventories have been at historically high levels lately as the supply of oil outstrips demand.

As the markets wound down, the price of benchmark U.S. crude oil was down $2.24 at $45.19 a barrel in trading on the New York Mercantile Exchange. In London, the price of Brent crude, the international standard for pricing oil, was down $2.28 at $46.52 a barrel.

ON THE MOVE. Stocks started higher, building on gains from the previous day. But they fell after a government report that showed oil stockpiles did not shrink as much as investors had hoped. Investors sold government bonds after buying them at a rapid clip earlier this week, and precious metals prices also slid. Energy companies were hammered as the price of oil dropped almost 5 percent.

ANALYST’S OPINION. Nate Thooft, head of global asset allocation for Manulife Asset Management, noted that stocks and oil prices have often traded in tandem this year. “Where oil goes, stocks go,” he said. “Oil fell dramatically pretty quickly.”