By Caitlin McCabe

Investors are struggling to predict where the stock market is headed next. Even so, many are already betting that health-care shares won't lead the way.

The sector offered shelter for investors -- followed by an outsize rebound -- during the market turbulence earlier this year. With several companies scrambling to create the first effective coronavirus vaccine or treatment, health-care stocks suddenly appeared to offer big opportunities for gains.

Lately, however, much of that allure has worn off. Fund managers have reduced their allocation to health-care stocks, and investors recently pulled more money from global health-focused equity funds than they have in nearly two decades.

The S&P 500's health-care sector finished June as the second-worst performer of the index's 11 groups, falling 2.5% compared with the benchmark's 1.8% gain. Companies from pharmaceutical giant Pfizer Inc. to biotech firm Biogen Inc. to health insurer Anthem Inc. dragged the sector down, all tumbling at least 10% during the month to rank among the biggest losers in the S&P 500.

Investors say the sector's recent losses reflect a growing list of concerns. Rising coronavirus infections have already halted elective surgeries in some parts of the country, eating into revenue as hospitals preserve capacity. Meanwhile, companies working on virus remedies are facing pressure to keep drug costs low. Investors are also beginning to fear a Democratic sweep in November's election that could lead to industry changes -- especially if a more progressive candidate is chosen to run as vice president.

"Contrary to what many would believe, Covid-19 is not a net positive for the sector," said David Kastner, senior investment strategist at Charles Schwab Investment Advisory. "It is simply less negative than it is for many sectors."

Even with the recent losses, the sector remains down just 0.3% in 2020, compared with the broad index's 3.1% decline.

This week, investors will look to earnings from the pharmacy chain Walgreens Boots Alliance Inc. to better understand the virus's effect on health-care companies. Traders will also be watching economic indicators such as the Institute for Supply Management's U.S. nonmanufacturing index for its assessment of the services industry.

Despite rising rapidly earlier this year, many biotech and pharmaceutical companies are now trading well below their 2020 highs. Investors initially flocked to companies working on virus vaccines and treatments, but trial results reveal the long road ahead. Investors are beginning to realize that many companies will struggle to find an effective remedy. And those that do will likely be pressured to keep their medicine affordable, limiting big opportunities for profit.

As a result, shares of Moderna Inc. and Inovio Pharmaceuticals Inc. -- both of which are working on a vaccine -- have fallen at least 26% from their highs this year. Gilead Sciences Inc., the drugmaker behind Covid-19 treatment remdesivir, is down 9.1% from its late-April high.

Meanwhile, investors are also trying to assess what a recent uptick in cases will bring. During the first spike of coronavirus infections this year, elective surgeries were dropped, doctors visits were canceled and clinics closed. That weighed on shares of hospitals operators such as Tenet Healthcare Corp. and HCA Healthcare Inc., which have badly trailed the broader market this year, off 52% and 34%, respectively.

The recent underperformance of the sector marks a contrast from earlier this year. During the selloff that began in mid-February, the S&P 500's health-care sector fell 28%, compared with the benchmark index's 34% decline. And then, after markets bottomed in late March, the group rallied 32% over the next month, outpacing the broader market. The stocks have, historically, been more resilient in recessions.

Evidence that traders were beginning to rotate out of the shares began emerging during the second quarter, when investors, including stuck-at-home day traders, began piling into cyclical stocks that careened in the early stages of the pandemic.

By mid-June, the exodus became more clear: Funds that focus on the health-care and biotechnology sector saw their 10-week inflow streak come to an end in the week ended June 10, according to EPFR Global data.

And by the following week, the situation had grown worse: The funds saw a record $2.6 billion of outflows -- an all-time high since EPFR began tracking the data in the first quarter of 2002.

Cameron Brandt, director of research at EPFR, said the exodus from health care is indicative of some profit-taking after a strong rally, and noted that inflows to the sector have since returned, though at much smaller levels than this spring. However, he added, the recent changes have coincided with a political shift, too: As money began flowing out of health- and biotechnology-focused funds, more national polls began showing that presumptive Democratic nominee Joe Biden was overtaking President Trump by a wider margin.

"Of the sector fund groups that tend to move in response to political shifts in the U.S., health care and financials tend to be the most sensitive," Mr. Brandt said.

"Two weeks ago was when the narrative of 'It's still possible that Trump will get re-elected' [shifted] to 'Trump will not and may take the Republican Senate down with him,'" he added. "And Democratic control is not viewed as a positive for the health-care sector."

Health-care stocks initially rallied in March at the prospect of Mr. Biden as the Democratic nominee because a massive overhaul of the health-care system would be less likely under his presidency. Even so, investors tend to view any kind of Democratic leadership as less favorable for business.

A June survey from Bank of America of roughly 200 fund managers showed that they view a Democratic 2020 sweep of the presidency and Congress as the third-biggest risk that markets are facing, following a second wave of coronavirus and permanently high unemployment.

The survey also revealed that fund managers' net allocation to the global health-care sector plummeted in June. The bank said a net 30% of respondents were overweight -- meaning they owned a larger position than the benchmark they track -- down from 48% in May.

In the coming weeks, traders say they will be watching to see whether rising coronavirus infections dent demand for health-care services and whether employment in the sector will continue to improve.

The June jobs report revealed that health-care employment increased by 358,000, led by gains in offices of dentists and physicians. However, job losses continued in nursing-care facilities, and employment in the sector remains far below February's levels.

Many investors and analysts said they aren't worried about any significant long-term dent in demand. Despite restrictions on elective surgeries in some states, other facilities have begun scheduling visits and procedures again. And unlike some sectors that may suffer from permanent changes in consumer behavior, demand for health care will persist, analysts and investors predict.

"A lot of the reduced revenue is artificial -- it's just the local governments that are stopping [health-care providers] from continuing their services," said Chris Zaccarelli, chief investment officer for Independent Advisor Alliance. "We believe as those restrictions are lifted, you'll see a lot of people come back...Health care will continue to be a good sector to invest in."

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

Corrections & Amplifications

This article was corrected at 6:17 p.m. ET to reflect that a June survey from Bank of America showed that fund managers view permanently high unemployment as one of the biggest risks that markets are facing. The original version incorrectly said they view permanently high employment as a risk.