But there have long been tantalizing hints that some amphibians can fight back. Some species, such as bullfrogs, haven’t declined despite being exposed to Bd. In other species, certain populations have vanished, while others have endured. In Australia, scientists have even discovered that a frog species that was decimated by Bd has been bouncing back.

Dr. Rohr and his colleagues wondered if these amphibians were developing immunity to the fungus. They might have a response similar to the way we develop immunity to influenza and other pathogens after exposure.

To find out, the scientists swabbed Bd onto the bellies of Cuban tree frogs. After the frogs became infected, the scientists cured them by taking advantage of a weakness of the fungus: it can’t survive for very long at high temperatures.

Dr. Rohr and his colleagues kept their frog chambers heated to 86 degrees for 10 days, after which the fungi disappeared. The scientists then repeated this procedure three more times.

Frogs that had already been exposed to Bd produced a much stronger immune response to a new infection, the scientists found. They produced more immune cells, and the fungus produced fewer spores.

The exposed frogs were also much more likely to survive an infection than a frog exposed for the first time. What’s more, these effects became stronger after each exposure.

Dr. Rohr and his colleagues also found that amphibians can learn to avoid the fungus. In another experiment, they put oak toads in a chamber. One side of the chamber was contaminated with fungal spores, while the other was fungus-free. They found that toads that had never been exposed to the fungus would explore both sides of the chamber, becoming infected along the way.