S&P 500 ends lower, capping blockbuster year with a whimper