Stocks ended a volatile trading session with solid gains, taking back some of the ground lost in the recent market rout.

The Dow Jones Industrial Average DJIA, -0.87% and the S&P 500 SPX, -1.11% each dropped more than 4% Monday for their biggest one-day percentage declines since August 2011, while erasing their 2018 gains. The Tuesday rebound put both back into positive territory for the year.