By Caitlin McCabe

Stocks are ripping higher, putting the S&P 500 on track for its best week in two months, as investors bet on a rapid economic recovery from the fallout of the coronavirus pandemic.

The benchmark U.S. stock index has surged 5.2% this week -- including a 2.9% gain Friday -- driven by shares of economically sensitive companies including banks and industrial and energy companies. The gains would mark the index's best week since the period ended April 9, when it climbed 12%.

The technology-heavy Nasdaq Composite index, meanwhile, is on pace to close at a record, fueled by the handful of big technology stocks that powered the nearly 11-year bull market.

Shares of Apple climbed 2.4% Friday, also on course for a new high, while Boeing added 10%, Exxon Mobil rose 10% and Citigroup increased 6.7%.

Predictions for a sharp, V-shaped recovery looked prescient after Friday's jobs report defied expectations and showed the economy added jobs last month. U.S. government bond yields surged, while gold prices tumbled. The moves in haven assets mark a shift from recent months when investors sought safety in bonds and gold, even as they pushed stocks higher.

Analysts said the jobs report offered the shot of adrenaline that traders needed to reinforce their hopes that the U.S. economy can recover even faster than anticipated from the coronavirus pandemic.

Yet the surging stock market also underscored what many critics have said is a disconnect between Wall Street and Main Street. Stocks have continued to rebound since late March despite dismal economic data, dwindling corporate earnings, rising tensions with China and a host of other worries.

Most recently, violent protests have erupted across the country following the death of George Floyd, a black man who was killed in police custody in Minneapolis. The breadth of the protests against the American justice system and the killing of black Americans marks a level of civil unrest that some say hasn't been seen in decades.

History, however, suggests that the market's behavior isn't unusual: Stocks tend to be unaffected by periods of civil unrest, natural disasters or other similar events -- especially if investors perceive that they show no signs of hurting the broader economy, analysts and traders say.

"There's a heck of a lot that the market is seemingly ignoring right now, in addition to the protests," said Liz Ann Sonders, chief investment strategist at Charles Schwab & Co. "But if you look back at the history of large-scale civil unrest...the market tended to sort of look through that. You didn't tend to see significant weakness either while it was happening or in the aftermath."

Take, for example, 1968 -- a year so volatile that Smithsonian Magazine dubbed it "The Year that Shattered America." Despite low unemployment and relatively low gas prices, tensions were building across the country. The U.S. was in the midst of the Vietnam War, inflation was rising and a viral influenza killed roughly 100,000 Americans. Racial tensions had been building for years by the time Martin Luther King Jr. was assassinated that April. His death set off a wave of nationwide rebellion.

Yet in the week following his death -- as the nation was enveloped in protest -- the S&P 500 rose 2.9%, according to Dow Jones Market Data. One month after his assassination, the benchmark index was up 5.1%. It gained 7.7% that year, defying all of the turmoil that the U.S. faced.

The protests that followed Mr. King's death were similar to the unrest happening across the U.S. today, said Heather Ann Thompson, a history professor at the University of Michigan who has studied policing and the criminal justice system.

"People had already been begging, pleading, protesting and sitting down nonviolently...so '68 was significant as this moment where it all comes to a head after King's assassination," Ms. Thompson said. She said the death of Mr. Floyd is a similar flashpoint after years of deaths of unarmed black Americans.

Similarly, the S&P 500 rallied 1.2% in the week after a jury in April 1992 found Los Angeles police officers not guilty of assault against Rodney King, a black man. A widely viewed video from a bystander had shown the officers beating Mr. King, leading to days of rioting in Los Angeles after the verdict. Still, the S&P 500 was up 0.8% one month after the jury's decision.

The benchmark index also rallied in the week and month after the August 2014 death of Michael Brown, an unarmed black teenager who was shot by a white police officer in Ferguson, Mo. His death also led to sustained protest and conversations about the dynamics between police and black Americans.

"The stock market is not something that necessarily goes up or down with the mood of the country," said Thomas Lee, co-founder and head of research at Fundstrat Global Advisors.

Some investors say the current rally highlights the forward-looking nature of stocks. Friday's labor data gave the clearest indication yet that the economic downturn created by the coronavirus may have already reached its trough. And promising early signs from drugmakers about their coronavirus vaccine progress have also given investors hope that life will be able to return to normal in the near future, enabling renewed consumer and business spending.

Meanwhile, massive intervention by the Federal Reserve, as well as anticipated additional stimulus measures from the U.S. government, has also buoyed markets.

Investors said that the markets have brushed off the civil unrest because any economic damage caused by the protests will pale in comparison with the harm inflicted by the virus. "The damage has already been done," said Brad McMillan, chief investment officer at Commonwealth Financial Network.

Write to Caitlin McCabe at caitlin.mccabe@wsj.com