S&P 500, Nasdaq close lower as traders cash in on latest megacap rally