Wall Street extended its rally for a third day on Tuesday as investors turned more conservative after last week's decline and embraced defensive shares.

The leading gainer among S&P 500 sectors was utilities, <.GSPU> which rose 1.2 percent.

The market earlier derived support from news of a trade surplus in China, which eased fears about global growth, and an $8.5 billion deal by Microsoft to buy Internet phone service Skype.

Investors are shifting gears from growth mode to more conservative dividend-paying stocks, said Randy Warren, chief investment officer at Warren Financial Service.

He said commodities have taken a real turn in the past few weeks, and that has had an impact on everything.

The Dow Jones industrial average <.DJI> was up 49.68 points, or 0.39 percent, at 12,734.36. The Standard & Poor's 500 Index <.SPX> was up 6.89 points, or 0.51 percent, at 1,353.18. The Nasdaq Composite Index <.IXIC> was up 15.80 points, or 0.56 percent, at 2,859.05.

The S&P was off 1.4 percent from its recent intraday high on May 2, which was the highest since early June 2008.

In the very short term, if we close above 1,354 which is the highs from three days ago, that might lead us higher in a constant pattern up to 1,370 soon, said Stephen Massocca, managing director at Wedbush Morgan in San Francisco.

Microsoft Corp said it plans to buy Internet phone service Skype for $8.5 billion in cash, a rich price as it seeks to regain ground on growing rivals such as Google Inc .

Microsoft shares were down 1.3 percent at $25.48 but shares of eBay Inc , which has a stake in Skype, rose 2.4 percent to $33.91.

China, the world's second-largest economy, posted an $11.4 billion trade surplus in April, nearly four times greater than expected, after exports hit a record on healthy demand and imports rose less than forecast.

China's export numbers were very good, said Burt White, chief investment officer at LPL Financial in Boston.

That gave a shot in the arm to this market.

Boston Scientific Corp was the most heavily traded stock on the Big Board after Chief Executive Ray Elliot said he will step down at the end of 2011. The surprise announcement sent shares of the medical device maker down 9.3 percent at $6.99.

Dean Foods Co jumped 12.3 percent to $12.33 after posting higher-than-expected quarterly profit.

Investors awaited results from Dow component Walt Disney Co .

(Reporting by Angela Moon, Editing by Kenneth Barry)