The S&P 500 and Nasdaq both finished slightly lower on Friday for weekly losses as Amazon.com shares slumped on disappointing earnings, while the Dow industrials finished at a record for a weekly gain.

The S&P 500 index SPX, +1.05% wrapped up down 3.32 points, or 0.1%, at 2,472.10, recovering from an earlier 10-point deficit, with eight of its 11 main sectors trading in negative territory led by a slump in consumer-staples as key components, tobacco maker Altria Group Inc. weighed on the group, with its shares down 9.5%, after the Food and Drug Administration announced a plan to reduce nicotine levels in cigarettes. The index finished at a less than 0.1% loss on the week.

The Dow Jones Industrial Average DJIA, +0.51% , which touched an all-time intraday high, rose 33.76 points, or 0.2%, to close at a record 21,830.31, shaking off an earlier 40-point decline. Shares of Chevron Corp. CVX, -1.00% led the average with a 1.9% gain after quarterly results, while shares of Exxon Mobil Corp., XOM, -2.47% finished down 1.5% after reporting disappointing second-quarter results. The blue-chip average rose 1.2% over the week.

The Nasdaq Composite Index COMP, +1.71% declined 7.51 points, or 0.1%, to close at 6,374.68, after an earlier decline of 45 points. The index finished down 0.2% on the week.

Less-than-spectacular corporate results from Amazon.com Inc. AMZN, +5.69% , which reported a 77% plunge in second-quarter earnings, added to a pause in the market’s gains as Wall Street reassessed valuations of the market’s highest fliers, which have helped equity benchmarks notch repeated records. Amazon shares declined 2.5%, having recovered from deeper losses earlier.

The pullback in the broader stock market came amid a few blemishes in relatively strong earnings season shows that investors who are skittish about high valuations are taking money off the table while those who are more confident of earnings growth are supporting levels, said Paul Nolte, portfolio manager of Kingsview Asset Management, in an interview.

“The fact that the market has recovered most of the losses from early this morning is healthy and we haven’t really seen it fallen much from its peak,” Nolte said.

Some analysts suggested that this week’s weakness was due to seasonal positioning.

“It is not surprising for market participants to take profits after a big rally, especially going into August, which is historically a difficult month,” said Quincy Krosby, chief market strategist at Prudential Financial.

Despite this week’s modest losses, the S&P 500 is up 2.1% since the start of the month and up 10.4% year to date.

The failure of a Republican-led attempt to repeal or replace the Affordable Care Act in the wee hours of Friday morning—viewed as a proxy for President Donald Trump’s ability to deliver on previously pledged pro-growth legislations—may also have dampened investor sentiment, some analysts said.

“The reality is that the clock is ticking for this administration to deliver something to their voters,” Krosby said. “Republicans also need to score victories before they hit the campaign trail, but so far, there is no sign of any tax relief that Trump voters have been expecting.”

Read:Amazon’s free-spending ways hit earnings, but don’t expect a shift to thrift

Some analysts suggested that any pullback in highflying “FAANG” stocks—Facebook Inc. FB, +2.66% , Amazon.com, Apple Inc. AAPL, +1.57% , Netflix Inc. NFLX, +0.78% and Google parent Alphabet Inc. GOOG, +2.39% GOOGL, +2.07% —which had been trading at high valuations, may provide the stiffest headwinds to further gains.

“If they lose momentum, something that is quite possible at any moment in time, which sectors are going to take over? In a market at record highs with [price-to-earnings] ratios the highest in a decade, that is a tough question to answer,” said James M. Meyer, chief investment officer at TowerBridge Advisors.

Economic docket: On the data front, a second-quarter reading on gross domestic product rose 2.6%, below the 2.8% expected by economists polled by MarketWatch. First-quarter GDP growth was revised to 1.2% from 1.4%.

The cost of employing the average U.S. worker rose 0.5% in the second quarter but showed little acceleration despite the tightest labor market in years.

The final reading of the University of Michigan’s consumer-sentiment survey for July was lifted to 93.4 from a preliminary 93.1. That’s a decline, however, from June’s level of 95.1.

Stocks to watch: Shares of Starbucks Corp. SBUX, +0.07% fell 9.2%. The company posted earnings above expectations and rising global sales. The coffee giant said it would close all of its Teavana retail stores over the coming year.

Expedia Inc. shares EXPE, +2.91% rose 3.4% after a revenue beat.

Merck & Co. Inc. MRK, -0.22% shares closed up 0.7% after the drug company reported quarterly results.

Align Technology Inc. ALGN, +0.08% shares surged 10% after the maker of Invisalign braces topped Wall Street estimates on earnings.

Other markets: European stocks SXXP, +0.20% finished at three-month lows as Swiss bank UBS Group AG UBSG, -0.19% fell on results and Asian stocks ADOW, -0.68% mostly fell Friday on the heels of that slump for U.S. tech stocks.

The dollar was back under pressure after the Senate health care vote and weaker-than-expected GDP numbers, with the ICE Dollar Index DXY, +0.34% down 0.6% to 93.29.

Gold prices US:GCQ7 rose 0.7% to settle at $1,268.40 an ounce, while oil prices US:CLU7 rose 1.4% to settle at $49.71 a barrel.

—Barbara Kollmeyer in Madrid contributed to this article.