The Nasdaq fell on Friday, halting a 12-day run-up, following Microsoft Corp's disappointing quarterly results, but gains in pharmaceutical and energy shares lifted the Dow and the S&P 500 to fresh 8-month closing highs.

Microsoft shares slid 8.3 percent to $23.45, a day after the software maker posted quarterly revenue below Wall Street's estimates. Web retailer Amazon.com Inc also missed sales expectations, driving its stock down 7.9 percent to $86.49.

The results cast a cloud over what is so far shaping up to be a stronger-than-expected second-quarter earnings season.

Even so, investors took Wall Street's initial drop on Friday as an opportunity to scoop up shares in other sectors, including energy and defensive plays such as big pharmaceuticals and utilities.

Microsoft is going through a product transition and no great visibility on the Windows franchise, but in general, the tone this quarter for a good many companies has been strong, said Owen Fitzpatrick, head of the U.S. equity group at Deutsche Bank Private Wealth Management in New York.

We are not probably going to see a major shift here in the negative direction, so it's probably going to be overall positive for earnings season.

The Dow Jones industrial average <.DJI> rose 23.95 points, or 0.26 percent, to 9,093.24. The Standard & Poor's 500 Index <.SPX> advanced 2.97 points, or 0.30 percent, to 979.26. But the Nasdaq Composite Index <.IXIC> shed 7.64 points, or 0.39 percent, to 1,965.96.

Microsoft was the top drag on both the Dow and the Nasdaq. Amazon.com was the Nasdaq's second-worst performer.

The Nasdaq's 12-day winning streak was its longest unbroken run since 1992.

INDEXES UP 4 PCT FOR THE WEEK

All three major U.S. stock indexes scored a second straight weekly advance, with the Dow rising 4 percent, the S&P 500 gaining 4.1 percent and the Nasdaq climbing 4.2 percent.

For the day, both the Dow and the S&P 500 hit their highest closes since early November 2008.

Since hitting a 12-year closing low of 676.53 on March 9, the S&P 500 has gained 44.7 percent. The Nasdaq, which closed at 1,268.64 on March 9, was up almost 55 percent from that level at Friday's close. The Dow has risen about 39 percent from its March 9 close at 6,547.05.

For the year, the Dow is up 3.6 percent, while the S&P 500 is up 8.4 percent and the Nasdaq is up 24.7 percent.

With 184 of the S&P 500 companies having reported second-quarter results through Friday, 77 percent -- or 142 companies -- have beaten forecasts, according to Thomson Reuters data.

GOOD RX FOR THE DOW

In Friday's session, shares of U.S. health care and consumer products company Johnson & Johnson shot up 2.1 percent to $61.51 and provided the top boost to the Dow. The second-biggest contributor to the Dow's advance was U.S. drugmaker Merck & Co , up 2.5 percent at $30.99.

The AMEX Pharmaceuticals index <.DRG> rose 1.4 percent.

Chevron Corp climbed 0.8 percent to $68.43 after U.S. front-month crude oil gained 89 cents, or 1.3 percent, to settle at $68.05 a barrel on the New York Mercantile Exchange. The S&P energy index <.GSPE> rose 1 percent.

In other earnings-related news, tool manufacturer Black and Decker Corp raised its full-year profit view, sending its shares up 10.1 percent to $37.13.

In Friday's session, the broad market's gains were curbed by a report showing U.S. consumer sentiment waned in late July to its lowest reading since April, according to the Reuters/University of Michigan Surveys of Consumers. [ID:nN24449821] The final July reading for the consumer sentiment index was 66.0, down from June's reading of 70.8.

Volume was light on the New York Stock Exchange, with only about 1.02 billion shares changing hands, well below last year's estimated daily average of 1.49 billion. On the Nasdaq, about 2.25 billion shares traded, just shy of last year's daily average of 2.28 billion.

Advancing stocks outnumbered declining ones on the NYSE by a ratio of about 9 to 5, while on the Nasdaq, about 5 stocks rose for every four that fell.

(Editing by Jan Paschal)