Stocks reversed their earlier gains in the final minutes of trading to close lower on the final trading day of February, but all major averages still finished higher for the month. The S&P 500 logged its fourth-straight month in positive territory.

Earlier, the Dow rallied to hit a fresh 5-year high, trading within less than 20 points of its all-time closing high.