Stocks closed out a solid week on Wall Street Friday with a late-afternoon rebound after worries that President Donald Trump would reignite a costly trade war with China faded.

The benchmark S&P 500 index rose 0.5%, recovering from a 1% slide, after Trump outlined several actions in response to a move by China to exert more control over Hong Kong but steered clear of upending a trade pact struck with Beijing earlier this year. The S&P 500 ended the month 4.5% higher, its second monthly gain in a row.

The world's two largest economies agreed to a Phase One trade deal in January after more than a year of talks and billions of dollars in tariffs imposed on each other's imports. Worries that the Trump administration would pull out of the deal with the world's second-largest economy weighed on the market for much of the day, until the president's midafternoon statement.

"Much ado about nothing," Sam Stovall, chief investment strategist at CFRA, said of the remarks. "The immediate concern, meaning the cessation of the Phase One [trade] accord, did not end up being put on the table, much to traders' relief."

Technology and health care stocks accounted for much of the market's gains. That helped offset losses in banks, industrial companies and elsewhere. Bond yields fell and gold prices rose, signs that investors remain cautious. Oil recovered from an early slide.

All told, the S&P 500 rose 14.58 points to 3,044.31. The index ended the week with a 3% gain. The Dow Jones industrial average fell 17.53 points, or 0.1%, to 25,383.11. The Nasdaq composite, which is heavily weighted with technology stocks, gained 120.88 points, or 1.3%, to 9,489.87. The Russell 2000 index of small company stocks gave up 6.64 points, or 0.5%, to 1,394.04.

Stocks have now recouped most of their losses after the initial economic fallout from the coronavirus pandemic knocked the market into a breathtaking skid in February and March, though the S&P 500 is still down 10% from its all-time high in February.

"We're in an incredibly fragile economy right now, and things are just getting back," said J.J. Kinahan, chief market strategist at TD Ameritrade.

On Thursday, China's National People's Congress approved a national security law aimed at suppressing secessionist and subversive activity in Hong Kong, overriding any potential opposition by local lawmakers.

In his remarks, Trump blasted China.

"Basically, he's going to treat Hong Kong the way he treats China," Stovall said.

Trump also said the U.S. would cut ties with the World Health Organization, saying it had failed to adequately respond to the coronavirus because China has "total control" over the global organization.

The move by China to get a tighter grip on Hong Kong could undermine the city's status as a major center for trade and finance. Hong Kong's Hang Seng Index finished 0.7% lower Friday.