Wall Street shares dropped for the third straight day on Tuesday as investors looked for signs of further gains in the energy sector.
But stocks rebounded to close the session with the Dow Jones industrial average and S&P 500 both hitting record highs.
The S&P 500 closed up 0.2 percent, or 1.9 points, to 1,094.55.
The Nasdaq index of small-cap stocks was up 0,734.43 points, or 2.5 percent, to 4,542.69.
The Russell 2000 index of smaller companies was up 2,826.71 points, more than 4 percent.
Shares in Exxon Mobil Corp. and BP Plc were off sharply, while Caterpillar Inc. fell 1.5.
Analysts polled by Reuters had forecast a loss of 1.1 percent for the S&ap, the best return since late-April.
Investors were looking for more signs of the coming boom in energy, as prices hit new highs, but there were mixed signals.
Energy stocks are now up more than 3 percent in 2017 and are expected to add more than 10 percent this year, according to data compiled by Bloomberg.
That was not enough to lift the S & P 500, which closed up 3.3 percent.
But analysts had been looking for an uptick in energy stocks as they have surged this year.
P 500 stocks were down 3.1% on Tuesday.
Oil and gas stocks fell as oil prices surged.
Chevron Corp. fell 5.9 percent, while ConocoPhillips fell 5 percent.
On the energy front, Exxon Mobil said it would cut 2,500 jobs this year as it tries to improve profits and keep its dividend from growing too much.
Energy stocks are expected hit their highest levels since 2014 and they are expected in the months ahead to benefit from rising oil prices.