By Paulo Trevisani and Jeffrey T. Lewis

More people are dying from Covid-19 in Brazil than anywhere else in the developing world, and the local economy is shrinking at the fastest pace in at least a century. Yet foreign investors are putting more money into Brazilian stocks than they are taking out for the first time in months.

As the country's currency plummeted during the coronavirus crisis, foreign investors put a net 343 million Brazilian reais ($65 million) in local stocks in June, the first month to see a net inflow since December, according to the local stock-market operator B3. That left foreign investors holding 47% of shares traded in Brazil, B3 said.

The Bovespa index is down 14% since January, compared with a decline of 6% in the MSCI emerging markets index -- a slide spurred by foreign investors selling emerging-market assets and seeking refuge in the dollar. June's net inflow is relatively small and comes amid a volatile time for global stocks. But it ends a rare six-month string of outflows and demonstrates investors' renewed appetite for potential bargains.

"One thing we do know is that (Covid-19) shall eventually pass," said trader James McDonald, CEO at Hercules Investments in Los Angeles. "If you buy a great asset for 30 cents on the dollar because it's temporarily experiencing a price shock, you eventually end up with a 300% plus return when the shock fades and the valuation returns to normal."

Mr. McDonald expects the health crisis to weigh on most Brazilian stocks through the second quarter of 2022. His fund has about $3 million in Brazilian shares out of around $200 million under management, and he plans to keep adding shares of local blue-chip companies. Those include beer giant Ambev SA (a unit of Belgium's Anheuser-Busch InBev SA/NV), airline Azul SA, shopping mall developer BR Malls Participações SA and university operator YDUQS Participaçoes SA.

Another major factor in investors' calculations: the Brazilian real has lost more value than any of its Latin American peers. It trades now at 5.26 per dollar, much weaker than 4 to the dollar in January.

As recently as 2016 a dollar bought only 3.10 reais. At the time, the Central Bank of Brazil's benchmark interest rate was 14.25%, attracting droves of yield-seeking investors. But as inflation got under control, the bank lowered rates to 2.25%.

The pandemic aggravated the Brazilian currency's trend, making the country's stocks look a lot cheaper in dollar terms. Some investors say Brazilian shares are even less risky than stocks in many developed markets.

"One can be quite convinced about Brazil," says Jerome Booth, chairman at New Sparta investment firm in London. He argues Brazilian assets are less likely to be inflated than those in developed countries, where large amounts of money were injected into the economy by central banks and governments to help ease the impact of the pandemic. "In that environment, emerging markets are reasonably well placed to be resilient sources of value."

Despite those investors' optimism, some analysts said they could be in for a bumpy ride.

Like its peers in the developed world, Brazil's central bank has slashed its benchmark rate and increased funds available for loans. But the scale in Brazil is much smaller. The Fed's balance sheet of $7 trillion is multiple times more than Brazil's entire gross domestic product.

Brazil's GDP will shrink 6.4% this year according to the central bank's most recent forecast, and will recover only partially in 2021. Unemployment and public debt, both already high even before the pandemic, are expected to show only limited improvement over the next few years.

"This is not enough growth for foreign investors," says Reinaldo Lacerda, a partner at Hieron Patrimônio Familiar e Investimento, an asset management firm in São Paulo that has clients in the U.S. and other countries. Mr. Lacerda doubts that June's net inflow into the stock market has legs. "Foreign investors won't have a sustainable return for now."

The devalued currency, however, seems to have a strong pull on global investors.

"There's a lot of bargain hunting on B3 now," said Marcos Casarin, Latin America economist at Oxford Economics.

He says until the currency strengthens past 4.26 per dollar, a level he doesn't see coming for several months, foreign investors should be able to find Brazilian assets at knockdown prices.

"There's an expectation of low interest rates for a long time," he said.

Write to Paulo Trevisani at paulo.trevisani@wsj.com and Jeffrey T. Lewis at jeffrey.lewis@wsj.com