Valero Energy Corp. said Tuesday that third-quarter profit fell 54 percent as the company was squeezed by thinner margins on gasoline and diesel and smaller discounts on certain types of crude oil that it refines.

Refining income declined sharply, but Valero’s ethanol business posted an operating profit, reversing a year-ago loss.