Baby corals and fish can smell the difference between good and bad reefs, according to a study based in Fiji.
When offered a choice of two water samples in the lab, the animals turned away from the stench of seaweed that invades depleted reefs, but were drawn to the smell of healthy coral.
It is the first time that corals have been shown to react over long distances to chemical "smells" in the water.
The findings suggest that controlling seaweed is key to repopulating reefs.
Once a coral reef has decayed and seaweed takes over, stopping fishing in the area may not be enough to bring the coral back.
"If you're setting up a marine protected area to seed recruitment into a degraded habitat, that recruitment may not happen if young fish and coral are not recognizing the degraded area as habitat," said Dr Danielle Dixson from the Georgia Institute of Technology, the study's first author.
Dr Dixson's research, published in the journal Science, made use of three marine protected areas off the coast of Fiji, which contain very healthy coral reefs but are immediately adjacent to heavily fished areas, dominated by seaweed.
"We've got these fished and un-fished areas that are small and immediately adjacent to each other, so it's a nice experimental setting," said Prof Mark Hay, the study's senior author.
Water from both healthy and weedy areas was taken to Prof Hay's lab, where fish placed in a special chamber were offered a choice between the two.
Very young fish from 15 different species all chose the water from the healthy coral reefs, spending more than 80% of their time on that side of the chamber.
Doing the same sort of test with coral was a ground-breaking experiment, Prof Hay said.
"For fish, people weren't too surprised that it happened, even as babies. They have tails, they have a nose. But for corals... they thought we were nuts."
The idea was challenging because baby corals are so simple. "They're kind of like bags of snot," Prof Hay told the BBC. "We didn't think it would happen either."
But sure enough, three species of coral larvae showed exactly the same behaviour, swimming into the better-smelling water by waggling their little hairs or "cilia".
"Dani and I were sitting around, smiling at each other and just laughing, going - can you believe this? This is so cool. Nobody's going to believe it. We better do a lot of replicates."
The researchers also identified the key ingredients, by mixing things up: if they contaminated water from a healthy reef with the smell of specific seaweeds, the fish would avoid it just as much as water from an abandoned reef.
Similarly, the aroma of certain healthy corals is enough to make bad water attractive.
Breaking the cycle
These results reveal new complexity in the way that coral behave.
Previous work had showed that coral larvae would settle in some places and not others, based on molecular cues. But researchers had only seen this happen over very short distances, when the coral effectively contact a good or bad surface.
"This is the first time that we've seen coral's ability to assess this on a large scale, when they're floating around," Prof Hay said.
"They can't do much against a current. So what we think is going on is that they're drifting through these different reefs, and if it smells good, they go down.
"It's a very strongly selected behaviour. Over aeons, there's been good reefs and bad reefs and if you settle on the bad ones, you die."
The discovery also indicates something of a vicious cycle, whereby fish and coral will not settle in an area unless it already contains other, healthy coral giving off the right odours.
The news is not all bad, however. If the seaweed giving off bad smells can be removed, and a previously abandoned area seeded with the most pleasantly perfumed coral, these new insights could help turn things around.
Tackling the seaweed is an important first step, and Prof Hay is working with villagers in Fiji on two strategies.
Certain fish eat these weeds, so he is encouraging the locals to avoid those species when spear-fishing. There is also hope of recruiting villagers to help physically clear the seaweed away, in the months before most coral larvae are looking to settle.
Prof Steve Widdicombe, head of science in Marine Life Support Systems at the Plymouth Marine Laboratory, said the findings had important implications.
"Having the right conditions is important. [These animals] are programmed to look for the places that they're going to be most successful in.
"It was very interesting to see this idea that if we're going to bring these habitats back, just leaving them alone might not be enough. We might have to make some active steps."
Follow Jonathan on Twitter