A rally in technology companies helped stocks overcome a shaky start Monday, extending Wall Street's solid gains from last week.

The S&P 500 rose 0.6% after initially sliding 0.6% following weakness in overseas markets as the global tally of coronavirus infections approaches 9 million. Investors are weighing the risks that rising coronavirus cases could pose to hopes for an economic recovery.

That’s led traders to bid up stocks in technology companies that offer services online, a thriving conduit of commerce through the outbreak. Investors are also favoring companies that are poised to do well now that more businesses have been given the go-ahead to reopen. Retailers like Gap, Best Buy and other companies that rely on consumer spending rose Monday, outweighing losses in health care, financial and other sectors. Airlines and cruise line operators were among the biggest decliners.

Traders are also continued to hedge their bets by snapping up traditionally less risky assets, such as government bonds and gold, which also rose. Bond yields were mixed.

The price of U.S. crude oil settled above $40 a barrel for the first time since early March, before the economy all but shut down completely due to the outbreak.

The S&P 500 gained 20.12 points to 3,117.86. The Dow Jones Industrial Average picked up 153.50 points, or 0.6%, to 26,024.96 after earlier sliding 203 points. The Nasdaq composite, which is heavily weighted with technology stocks, climbed 110.35 points, or 1.1%, to 10,056.47, extending its winning streak to a seventh day.

Small company stocks, which have lagged the broader market’s rebound that began in April, also notched solid gains. The Russell 2000 index added 14.89 points, or 1.1%, to 1,433.53.

The S&P 500 was coming off its fourth weekly gain in the past five weeks. Encouraging economic data, including retail sales and hiring, have helped stoke optimism among investors that the reopening of businesses in the U.S. and other countries will pull the economy out of its recession relatively quickly. But a rise in new coronvairus cases is clouding the prospects for an economic recovery. On Friday, stocks sold off after Apple said it would be temporarily closing 11 stores again in four states, citing a surge in new virus cases.

“The path of the virus remains uncertain, but the market has certainly gone up and recovered to some degree as though it’s going to go OK,” said Tom Martin, senior portfolio manager with Globalt Investments.

The World Health Organization on Sunday reported the largest single-day increase in coronavirus cases by its count, at more than 183,000 new cases in the previous 24 hours. The U.N. health agency said Sunday that Brazil led the way with 54,771 cases and the US next at 36,617. India confirmed 15,400 new cases.

The United States also reported more than 30,000 new coronavirus cases on Friday and Saturday, with the daily totals their highest since May 1. A large share of the cases are in the South, West and Midwest, where hospitals in some areas are becoming overwhelmed. Case numbers in South Korea and China, meanwhile, have appeared to be moderating after recent outbreaks centered in their capitals.

Many professional investors have been warning that the S&P 500′s big rally of nearly 40% since late March has been overdone and that volatility is likely the market’s only certainty in upcoming months. The market began its turnaround following a nearly 34% sell-off in February and March after the Federal Reserve promised massive amounts of aid for the economy.

While recent economic data have shown improvement, reflecting the reopening of businesses, it may take years for the economy to fully recover. In contrast, it took just a few months for the stock market to rally back to within 9% of its record.

David Kelly, chief global strategist at JPMorgan Funds, sees a disconnect between the market's recent gains and what the economic data show. He says the markets seem to be straying further and further from fundamentals, which is making him “more distrustful of markets as an economic barometer.”

New data on home sales Monday show the virus outbreak continues to disrupt the U.S. housing market. Sales of previously occupied homes plunged 9.7% in May, according to the National Association of Realtors. The May slide pushed sales down to a seasonally adjusted annual rate of 3.91 million, the slowest pace since 2010. Still, the median home price rose 2.3% from a year ago, a sign that demand could pickup up in coming months. Homebuilder shares moved broadly higher. KB Home gained 3.7%.

Investors will get a broader look at the state of the economy toward the end of this week, when the government issues data on consumer spending, weekly unemployment aid applications and durable goods orders. On Tuesday, the Commerce Department serves up new home sales figures for May.

The yield on the 10-year Treasury note held steady at 0.70% after falling earlier in the day. It tends to move with investors’ expectations for the economy and inflation.

In commodities trading, the price of gold rose 0.8% to $1,766.40 an ounce. Oil prices also finished higher. Benchmark U.S. crude oil for July delivery rose 71 cents to settle at $40.46 a barrel for the first time since March 6. Brent crude, the international standard, rose 89 cents to $43.08 a barrel for August delivery.

European markets closed broadly lower. Britain’s FTSE 100 lost 0.8% and the CAC 40 in Paris fell 0.6%. Germany’s DAX slid 0.5%. Asian markets also fell overnight.