William Ackman just scored big on a bearish bet that enabled him to sidestep steep market losses.

About a month ago, Mr. Ackman laid out $27 million to protect his portfolio against a precipitous drop he anticipated in U.S. markets as a result of the coronavirus outbreak. Those so-called hedges came in the form of credit protection on global investment-grade and high-yield bond indexes that becomes more valuable as the likelihood of corporate defaults rises.

He said in a letter to investors in his Pershing Square Capital Management LP released Wednesday that he has now closed those hedges, generating $2.6 billion in proceeds.

That offset losses in his portfolio and enabled Pershing Square’s public fund to notch a 7.9% gain in March through Tuesday’s close, a period in which the S&P 500 lost 17%. For the year, the fund is up 0.2%.

Mr. Ackman said in an interview Wednesday that as he watched the virus spread in China, it became clear to him the only way to deal with it was to take drastic action and shut down the economy. In February, as many others were still dismissive of the risk in the U.S., Mr. Ackman sought to protect his portfolio.