NEW YORK - Oil prices closed above the $140-a-barrel mark yesterday for the first time as investors continued to spurn the stock market in favor of commodities.

"The trend to hard assets, and energy in particular, is unabated," said John Kilduff, a vice president at MF Global Ltd. in New York. "There's a lack of confidence in stocks and other markets right now, which has investors looking for safe havens."

With oil passing $140, traders are now expecting to see $145 and even $150, analysts said.

Light, sweet crude oil for August delivery rose as high as $142.99 a barrel on the New York Mercantile Exchange before pulling back in a spate of late-day profit-taking. It closed up 57 cents for the day at a record $140.21 a barrel.

The price of oil has increased 38 percent in the current quarter as the dollar fell against the euro. The dollar was down again yesterday, confirming expectations that it will extend its decline and add to oil's appeal.

The oil price is heading for its biggest quarterly gain since the first three months of 1999, when it traded between $11 and $17 a barrel.

"I don't know when this really will end because there are too many folks in the finance community betting on prices to rise," said Rick Mueller, director of oil practice at Energy Security Analysis Inc. in Wakefield, Mass. "Gains have nothing to do with the physical market."

Retail gas prices nationally were unchanged yesterday at an average of $4.07 a gallon. But they're likely to resume their own trek into record territory now that oil futures have broken out of the trading range in the $130s, where they had been for nearly three weeks.

In Philadelphia and its four suburban counties in Pennsylvania, the average for regular-grade gasoline rose a penny yesterday to $4.15 a gallon, AAA Mid-Atlantic said. The average was unchanged at $3.97 in the three suburban counties in South Jersey.

In currency trading, the dollar was stable early in the day but fell later against the euro.

"The dollar was slightly stronger, and when it gave up its gains, that gave oil the green light," said James Cordier, president of Tampa, Fla.-based trading firms Liberty Trading Group and

The market now believes the Federal Reserve is unlikely to raise interest rates in the near future. Since higher rates tend to strengthen the dollar, traders are anticipating that it will continue to fall and, consequently, that investors will keep turning to commodities, including oil, as a hedge against inflation.

"Oil's back in favor, especially with people bailing out of the stock market," said Jim Ritterbusch, president of energy consultancy Ritterbusch & Associates, in Galena, Ill.

The stock market's recent swoon is sending investors in search of higher-yielding investments. On Thursday, the Dow Jones Industrial Average fell nearly 360 points, and it dropped an additional 106 points yesterday.

Gas prices have fallen slightly from their June 16 record of $4.08 a gallon nationally, but they will likely resume their rise if oil futures keep trending higher.