SAN ANTONIO ( TheStreet) -- Valero Energy ( VLO), the country's largest refiner, swung to a loss in the second quarter as demand for refined products waned and refining margins shrank.

On Tuesday, the San Antonio-based concern reported a net loss of $254 million, or 48 cents a share, compared to a net income of $734 million, or $1.37 a share, in the year-ago period.

Analysts surveyed by Thomson Reuters anticipated the company to report a 50 cent per share loss.

Operating revenues also fell more than 50% from last year's second quarter to come to $17.9 billion this year, though that still beat most forecasts.

According to a press release, Valero posted a $317 million operating loss resulting from lower margins for diesel and jet fuel, along with lower sour crude oil differentials. In the year-earlier quarter, the company's operating income came to $1.2 billion.

Still, away from the refining carnage, operating income for Valero's retail segment jumped to $65 million from $49 million in the year-ago.

"This is a very challenging environment for sour crude oil refiners," Valero CEO Bill Klesse said in a press release.

"The downturn in the global economy has sharply reduced demand for refined products at a time when new refining capacity is coming online around the world. Also, sour crude oil differentials have narrowed mainly because key supplies of lower quality crude oils have come off the market."

"As a result," Klesse continued, "global product inventories are high and refining margins are depressed. When the global economy improves, we expect that product demand, sour crude oil production, and refining margins will also improve."

After the announcement and just before the opening bell, Valero shares were losing 56 cents, or nearly 3%, to $18.21.

--Reported by Sung Moss in New York.
Copyright 2009 TheStreet.com Inc. All rights reserved. This material may not be published, broadcast, rewritten, or redistributed.