Chemical warfare including insecticidal secondary metabolites is a well-known strategy for environmental microbes to monopolize a food source. Insects in turn have evolved behavioural and physiological defences to eradicate or neutralize the harmful microorganisms. We studied the defensive repertoire of insects in this interference competition by combining behavioural and developmental assays with whole-transcriptome time-series analysis. Confrontation with the toxic filamentous fungus Aspergillus nidulans severely reduced the survival of Drosophila melanogaster larvae. Nonetheless, the larvae did not behaviourally avoid the fungus, but aggregated at it. Confrontation with fungi strongly affected larval gene expression, including many genes involved in detoxification (e.g., CYP, GST and UGT genes) and the formation of the insect cuticle (e.g., Tweedle genes). The most strongly upregulated genes were several members of the insect-specific gene family Osiris, and CHK-kinase-like domains were over-represented. Immune responses were not activated, reflecting the competitive rather than pathogenic nature of the antagonistic interaction. While internal microbes are widely acknowledged as important, our study emphasizes the underappreciated role of environmental microbes as fierce competitors.