Investors looked past weeks of grim economic news to power Wall Street to its best month in decades, even as the three major U.S. indexes ended Thursday’s session in the red.

The Standard & Poor’s 500 posted its strongest one-month returns since 1987, at a time when the nation’s economy shriveled and 30 million jobs were lost amid the coronavirus pandemic. The gains came even as covid-19 deaths surpassed 60,000 on Thursday.

The broad index closed out April roughly 12 percent higher than it started. The blue-chip Dow Jones industrial average wrapped up with a 10 percent gain, its best month since January 1987. The tech-heavy Nasdaq composite surged 14 percent in April.

Investors have largely kept their eyes on economic rescue efforts by Washington and the central bank, which flooded Wall Street and Main Street with trillions of dollars in stimulus. The government pledged to backstop businesses, provide for the unemployed, rescue a grounded commercial air fleet and help most adults with one-time payments topping out at $1,200. Federal Reserve Chair Jerome H. Powell, meanwhile, has repeatedly said the central bank would do whatever it takes to support the economy.

“The bottom line is, don’t fight the Fed and don’t fight the government,” said Kenny Polcari of SlateStone Wealth. “We are where we are because of the massive unconditional programs the government has implemented and has promised to implement. There will be a re-pricing of stocks down the road, so enjoy this while it lasts.”

For the day, the Dow shed 288.14 points, just over 1 percent, to close at 24,345.72. The S&P 500 fell 27.08 points, or 0.9 percent, to 2,912.43. The Nasdaq slipped 25.16 points, or 0.3 percent, to finish at 8,889.55.

April followed one of Wall Street’s worst months since the Great Depression, so analysts were not surprised by the recovery.

“We were at recessionary lows,” said Howard Silverblatt of S&P Dow Jones Indices. “This is an excellent month, considering we had 30 million people apply for unemployment checks. But remember, we were down over 12 percent in March.”

Wall Street is in the thick of earnings season. The big tech giants — Microsoft, Apple, Amazon, Facebook and Alphabet, the parent company of Google — all reported this week. Alphabet, Microsoft and Facebook shares rose during the week after the companies released results, showing resilience in the midst of a pandemic that has brought much of the economy to a crawl.

On Thursday, Apple reported better-than-expected revenue of $58.3 billion, on iPhone sales of $28.96 billion, in the second quarter. It earned $11.25 billion, or $2.55 per share. Apple’s shares were down slightly in after-hours trading.

Amazon reported sales of $75.5 billion for the first quarter, a 26 percent increase over the same period last year. Profit dropped 29 percent from last year, to $2.5 billion. The company benefited from a big increase in the number of sales from customers who ordered from home during the coronavirus lockdown. (Amazon founder and CEO Jeff Bezos owns The Washington Post.)

Several investors say that the market gains make no sense given the economic climate but that Wall Street has locked onto health advances against the coronavirus and a gradual reopening of the country. Those investors are gauging an upswing in the second half of the year.

“Investors are whistling past the graveyard as they are focused on the hopes of a better economy next year given the massive stimulus packages being developed,” said Wayne A. Wicker, chief investment officer of Vantagepoint Investment Advisers.

Small medical advances sprinkled investors with hope the past two weeks as pharmaceutical companies worked on virus vaccines and treatments. It became a shower on Wednesday after Gilead Sciences reported “positive data” in a clinical trial by the National Institute of Allergy and Infectious Diseases for remdesivir, a possible covid-19 treatment.

The trial showed that “a drug can block this virus,” Anthony S. Fauci, director of the institute, said in a news conference Wednesday. The Food and Drug Administration said Thursday it was working at “lightning speed” to get remdesivir to coronavirus patients.

U.S. gross domestic product contracted 4.8 percent in the first quarter, the Commerce Department reported Wednesday. The decline is the biggest since the 2008 financial crisis, but the worst is still to come, as the full impact of the pandemic had not manifested in the first quarter. Economists are predicting a contraction of as much as 35 percent in the second quarter.

Oil prices continue to rise on optimism toward a reopening and on fresh data from the American Petroleum Institute showing that crude storage was not filling as quickly as feared. West Texas Intermediate, the U.S. oil benchmark, was up more than 23 percent to trade at $18.60 a barrel. Brent crude, the international oil benchmark, climbed more than 12 percent to $25 a barrel.

Silverblatt said the fits and starts of virus health applications and the various unwinds of the lockdowns, state by state, will come into full view during May. He predicts lots of volatility to come.

“There’s been a lot of trading on hope,” Silverblatt said. “Reality will set in during May.”