By Anna Isaac and Juliet Chung

U.S. stocks rose Friday as a slate of technology giants buoyed the S&P 500 and offset disappointing earnings from some industrials and weak economic data.

The S&P 500 climbed 25 points, or 0.8%, to 3,271.12, on Friday, closing out July with a 5.5% gain for the month. The bellwether index has now rallied for four straight months, marking its largest four-month percentage gain since December of 1998.

The Dow Jones Industrial Average rose 115 points, or 0.4%, to 26,428.32, marking its fourth consecutive monthly gain.

The tech-heavy Nasdaq Composite rose 157 points, or 1.5%, to 10,745.27.

Apple, Facebook and Amazon.com were among the index's biggest winners Friday, rising 10.5%, 8.2% and 3.7% on the back of strong earnings.

Their gains offset stock price declines by Chevron, which posted steep losses in the second quarter as the drop in global travel crimped fuel demand amid the pandemic. Caterpillar also fell after reporting that its revenue in the U.S. dropped more than 40% in the second quarter.

Overall, however, U.S. stocks were modestly higher Friday, capping off a week of swings in major indexes as investors parsed Federal Reserve Chairman Jerome Powell's comments, a slate of mixed corporate earnings and grim economic data showing the economy contracted as a record rate last quarter. A late rally helped stocks lock in gains for the day on Friday.

Greg Dowling, chief investment officer at Cincinnati, Ohio-based Fund Evaluation Group, said he viewed the volatility as a partial reflection of big institutional investors sitting on the sidelines.

"They're waiting for stimulus, waiting for the election and waiting for earnings clarity," Mr. Dowling said, adding their opting out has contributed to thin trading volume and volatility in stock prices.

Once large U.S. technology stocks are set aside, the mixed picture for global equities reflects a continuing tug of war in markets, according to investors.

"The push-pull factors remain the same," said Edward Park, deputy chief investment officer at Brooks Macdonald. "We've seen incremental vaccine improvements but the market seems to have priced that in for the medium term. But there is still the risk of a second wave, or an elongated first wave of the virus, deepening China-U. S. tensions and heightened anti-China rhetoric from western allies of the U.S."

Concerns about the health of the American economy were underlined by Congressional leaders and White House officials failing to strike a deal on coronavirus relief Thursday night, just hours before federal jobless benefits officially expired Friday.

Consumer spending, a crucial indicator for the economy's path in the coming months, rose 5.6% in June but appears to have weakened in recent weeks, restraining the economic recovery from the coronavirus outbreak.

The U.S. dollar rebounded slightly after declines earlier this week, according to FactSet. The ICE U.S. dollar index, which measures the greenback against a basket of currencies, rose 0.4%. Concern over U.S. economic performance, following a sharp contraction in the second quarter, have been weighing on the currency, analysts said.

Meanwhile new coronavirus cases in the U.S. climbed back above 70,000 as daily reported deaths rose to their highest level in more than a month Thursday, according to data compiled by Johns Hopkins University.

"I do suspect that the rush to sell the dollar is now looking a bit overdone. I would anticipate some pullbacks," said Jane Foley, senior currency strategist at Rabobank.

Overseas, the pan-continental Stoxx Europe 600 fell 0.89% Friday from its prior close. That index is down nearly 11 points, or 3%, for the week, its second down week in a row. For the year through July, it is down 59.5 points, or 14.3%.

Jane Buchan, chief executive of Newport Beach, Calif. investment firm Martlet Asset Management, said the strong performance of the tech giants despite several of their executives being interrogated by Congress this week reflected investors' focus on where the economy was headed.

"This whole pandemic has been a quick peer into the future and what the world could look like in two or three years. It's sped up the transition to a New Economy and we're figuring out which are the businesses that are going to be really successful in that economy," she said.

Futures contracts for delivering gold in August rose 1.1% to $1,962.80 a troy ounce. The metal, a traditional haven for investors, marked its largest one month percentage gain since February 2016.

The yield on the benchmark 10-year U.S. Treasury ticked down to 0.536% Friday, down from 0.540% on Thursday.

In the Asia-Pacific region, stocks painted a mixed picture by the close of trading. China's major equity benchmark, the Shanghai Composite Index, rose 0.7%. Japan's Nikkei 225 index fell 2.8%, and Australia's S&P ASX 200 index dropped 2%. Both countries face fresh outbreaks of coronavirus after previously managing to contain infections earlier this year.

Write to Anna Isaac at anna.isaac@wsj.com and Juliet Chung at juliet.chung@wsj.com