The S&P 500 ended higher after a brutal two-day sell-off, led by a rebound in energy and technology shares, but the market faltered toward the session's end as Apple shares surrendered gains ahead of the Thanksgiving holiday.

The S&P 500 ended higher after a brutal two-day sell-off, led by a rebound in energy and technology shares, but the market faltered toward the session's end as Apple shares surrendered gains ahead of the Thanksgiving holiday.