The S&P 500 slumped more than 2 percent for the first time in six months, rattling investors after a long stretch of gains.