By Anna Hirtenstein, Gunjan Banerji and Chong Koh Ping

The S&P 500 rose Friday and notched a big weekly gain as states around the country eased coronavirus restrictions, boosting hopes about an economic recovery.

Major indexes declined early in the day before reversing course or paring losses. The S&P 500 added 6.94 points, or 0.2%, to 2955.45. The Nasdaq Composite gained 39.71 points, or 0.4%, to 9324.59. The Dow Jones Industrial Average edged down 8.96 points, or less than 0.1% to 24465.16.

Despite the relatively muted moves, all three major indexes gained at least 3% this week, in part driven by optimism that coronavirus vaccines will be available later this year. Additionally, all 50 states have relaxed some of their coronavirus restrictions, stirring hopes about an economic rebound as municipalities start to reopen.

The S&P 500 and Dow added 3.2% and 3.3%, respectively, for the week, while the Nasdaq climbed 3.4%.

The moves this week mark a continuation of an impressive stock rebound since major indexes' lows in March, as investors have looked ahead to a potential bounceback in the domestic economy despite abysmal data that has shown the extent of the current downturn.

Markets are closed Monday for Memorial Day in the U.S.

"We've been aggressive buyers" of stocks, said Dev Kantesaria, founder of Valley Forge Capital Management, which oversees about $750 million in assets. "I believe a year from now we will be back..almost at old levels for the economy."

Mr. Kantesaria added that he's expecting weakness in parts of the economy, but remains broadly optimistic about a recovery.

Still, some of the confidence that drove major indexes higher earlier in the week abated Thursday as investors parsed new data showing that about 2.4 million Americans filed for unemployment benefits in the week ending May 16, continuing a sharp deterioration in the labor market. On Friday, some of the simmering tensions between the U.S. and China escalated, weighing on global stocks.

The Hang Seng Index closed down 5.6% in its worst day since July 2015 after China moved to impose new national-security laws on the city.

China scrapped its economic growth target for 2020 in a stark acknowledgment of the challenges facing the world's second-largest economy, sending crude oil and metal prices sharply lower.

"Anything that knocks China's growth rate, whether it's a slower recovery from the coronavirus or a rise in tensions with the U.S., will weigh on global growth expectations," said Seema Shah, chief strategist at Principal Global Investors.

Beijing's decision to omit a formal target comes amid the sharpest contraction in four decades precipitated by a sudden halt in manufacturing activity because of the coronavirus pandemic. The nation's policy makers are signaling that they won't rush to introduce additional stimulus measures, which suggests more economic pain for countries that have become increasingly reliant on China as an engine of growth.

China's proposed national security law would challenge the financial hub's autonomy and threatens to increase tensions with the U.S. Congress condemned the move, with senators promising an urgent push on legislation that would impose sanctions on Chinese officials and institutions involved in undermining Hong Kong's Western-style rule of law.

The yield on the 10-year U.S. Treasury note rose to 0.659% on Friday from 0.640% last week as bond prices rose.

Brent crude, the global oil benchmark, fell 2.6% on Friday to $35.13 a barrel. Copper, a closely watched metal for its use in industrial activity, slipped 1.8%.

"China is today the biggest importer of crude oil, so Chinese growth is hugely important for oil demand," said Bjarne Schieldrop, chief commodities analyst at Nordic bank SEB. "But at the same time, demand is ticking up and supply is ticking down," as Asian countries reopen, he said.

In Asia, most major stock benchmarks ended the day lower. China's Shanghai Composite Index fell 1.9% while South Korea's Kospi Index retreated 1.4%.

Write to Anna Hirtenstein at anna.hirtenstein@wsj.com, Gunjan Banerji at Gunjan.Banerji@wsj.com and Chong Koh Ping at chong.kohping@wsj.com