Stocks ended lower on Wall Street Monday, but the market still closed out August with its fifth monthly gain in a row.

The S&P 500 fell 0.2% after spending much of the day wavering between gains and losses of less than 0.1%. The modest decline, which snapped the index’s seven-day winning streak, came as losses in financial, industrial and energy companies outweighed gains in technology stocks.

The benchmark index finished the month with a 7% gain, making it the S&P 500′s best August since 1986. It’s now up 8.3% this year. The Nasdaq composite, meanwhile, added to its recent string of milestones, closing at an all-time high.

The market’s latest strong monthly finish extends a remarkable comeback for Wall Street since the coronavirus pandemic knocked financial markets into a steep skid and the global economy into recession.

Encouraging economic data as broad swaths of the economy have reopened this summer have helped stoke investor optimism about a recovery. The question is whether that’s going to be enough to keep the market moving higher when so much uncertainty remains about the pandemic’s lasting impact on companies and consumers.

“People need to be careful here because what we have is an exuberant rally sitting on the foundation of a shaky recovery,” said David Kelly, chief global strategist at JPMorgan Funds. He added that there will likely be a market correction “that brings us back down to Earth.”

The S&P 500 fell 7.70 points to 3,500.31. The Dow Jones Industrial Average lost 223.82 points, or 0.8%, to 28,430.05.

The Nasdaq rose 79.82 points, or 0.7%, to 11,775.46. The index, heavily weighted with tech stocks, has led the market’s rebound this year. It finished August with a 9.6% gain and it’s up 31.2% for the year. The Russell 2000 index of small company stocks fell 16.47 points, or 1%, to 1,561.88.

Low interest rates and massive amounts of bond purchases by the Federal Reserve have helped prop up the economy, and they’re a central reason the S&P 500 has been able to recover from its nearly 34% plunge earlier this year, even though the pandemic is still raging.

Congress has also offered unprecedented amounts of aid, though it’s hit a seeming impasse in negotiations to re-up its assistance. Weekly benefits that it approved earlier for unemployed workers have run out, and investors say the economy desperately needs another lifeline from Capitol Hill to carry it through its current weakness.

Investors have been largely willing to look a few months or a year into the future, when a vaccine for the new coronavirus will hopefully be available and helping the economy get back to normal. The market is also betting that corporate profits will rebound next year from their current coronavirus-caused hole.

Still, the economy, which despite strong housing sector growth and modest improvements in retail sales and unemployment, remains in a deep recession — a stark contrast to Wall Street’s roaring comeback the past five months.

Part of the reason some of the recent economic reports have been strong, such as retail sales, is that the figures were bouncing back from steep declines due to the broad shutdown of businesses in the spring. Economic data in the next few months are not likely to be as eye-popping, said Megan Horneman, director of portfolio strategy at Verdence Capital Advisors.

“We’re here because of the euphoria around some of the economic numbers as the economy has reopened,” she said. “The second half of this year, the last quarter of this year, is going to be a bit more challenging for the (stock) market than we’ve seen over the past three months.”

Another factor that may weigh on the market is history. Since 1950, September has been, on average, the weakest month of the year for stocks, according to LPL Financial. And the last two times that the S&P 500 ended August ended with a gain of more than 5% it went on to lose all of those gains in September.

“Well, 2020 has laughed at many of these things, but be aware September is indeed the worst month of the year on average,” Ryan Detrick, chief market strategist at LPL Financial, wrote in a commentary.

Monday was the first day of trading in the Dow since the 30-company average had its lineup of companies revamped. Salesforce.com, Amgen and Honeywell International are replacing Exxon Mobil, Pfizer and Raytheon Technologies. The shuffle was triggered by a 4-for-1 stock split in Dow member Apple. Tesla also had a 5-for-1 stock split that took effect Monday. Apple was up 3.4%, while Tesla vaulted 12.6%.

Markets in Europe closed broadly lower. The DAX in Germany fell 0.7%, while the CAC 40 in France lost 1.1%. Stock markets in the United Kingdom were closed for a holiday.

The yield on the 10-year Treasury slipped to 0.70% from 0.72% late Friday.

Oil prices fell. Benchmark U.S. crude oil for October delivery fell 36 cents to $42.61 a barrel Monday. Brent crude oil for November delivery dropped 53 cents to $45.28 a barrel.

Asian markets closed broadly lower except for Japan, where the market got a boost by gains for five major trading companies after investor Warren Buffett’s Berkshire Hathaway announced it bought stakes of just over 5% in those companies. Gains in Japanese factory output also helped lift sentiment.