Coral reefs are intricate ecosystems that harbor diverse organisms, including 25% of all marine fish. Healthy corals exhibit a complex symbiosis between coral polyps, endosymbiotic alga, and an array of microorganisms, called the coral holobiont. Secretion of specialized metabolites by coral microbiota is thought to contribute to the defense of this sessile organism against harmful biotic and abiotic factors. While few causative agents of coral diseases have been unequivocally identified, fungi have been implicated in the massive destruction of some soft corals worldwide. Because corals are nocturnal feeders, they may be more vulnerable to fungal infection at night, and we hypothesized that the coral microbiota would have the capability to enhance their defenses against fungi in the dark. A Pseudoalteromonas sp. isolated from a healthy octocoral displayed light-dependent antifungal properties when grown adjacent to Penicillium citrinum (P. citrinum) isolated from a diseased Gorgonian octocoral. Microbial MALDI-imaging mass spectrometry (IMS) coupled with molecular network analyses revealed that Pseudoalteromonas produced higher levels of antifungal polyketide alteramides in the dark than in the light. The alteramides were inactivated by light through a photoinduced intramolecular cyclization. Further NMR studies led to a revision of the stereochemical structure of the alteramides. Alteramide A exhibited antifungal properties and elicited changes in fungal metabolite distributions of mycotoxin citrinin and citrinadins. These data support the hypothesis that coral microbiota use abiotic factors such as light to regulate the production of metabolites with specialized functions to combat opportunistic pathogens at night.