The S&P and Nasdaq declined on Tuesday as investors sold commodity-related shares, and saw the market digressing further from its recent rally.

Shares of Alcoa Inc shares, however, shot up 3.7 percent to $17.86 and helped to support the Dow, on market talk that Rio Tinto was lining up a bid to buy the U.S. aluminum company. Options activity also rose, though neither Alcoa nor Rio Tinto would comment on the rumors.

The energy sector, which gained 16 percent in the first quarter, led losses on the S&P 500. The S&P energy index <.GSPE> was down 1.6 percent.

You've had a tremendous run up here, so you've got some profit-taking and an underlying rotation, out of commodity-related shares and into more defensive areas, said Paul Mendelsohn, chief investment strategist at Windham Financial Services in Charlotte, Vermont.

But he said he sees any pullback as short-term and expects the market to remain on an upward trend. The S&P is up nearly 30 percent since the start of September, when the recent rally began.

The Dow Jones industrial average <.DJI> was up 16.42 points, or 0.13 percent, at 12,823.78. The Standard & Poor's 500 Index <.SPX> was down 2.84 points, or 0.21 percent, at 1,358.38. The Nasdaq Composite Index <.IXIC> was down 16.47 points, or 0.58 percent, at 2,847.61.

MasterCard Inc rose 2.8 percent to $283 after the world's second-largest credit card processing network posted a 24 percent jump in quarterly profit.

(Additional reporting by Chuck Mikolajczak)

(Reporting by Caroline Valetkevitch)