In addition to its canonical function of protection from pathogens, the immune system can also alter behaviour1,2. The scope and mechanisms of behavioural modifications by the immune system is not yet well understood. Here, using mouse models of food allergy, we show that allergic sensitization drives antigen-specific avoidance behaviour. Allergen ingestion activates brain areas involved in the response to aversive stimuli, including the nucleus of tractus solitarius, parabrachial nucleus, and central amygdala. Allergen avoidance requires IgE antibodies and mast cells but precedes the development of gut allergic inflammation. The ability of allergen-specific IgE and mast cells to promote avoidance requires cysteinyl leukotrienes and growth and differentiation factor 15 (GDF15). Finally, a comparison of C57BL/6 and BALB/c mouse strains revealed a strong effect of the genetic background on the avoidance behaviour. These findings thus point to antigen-specific behavioural modifications that likely evolved to promote niche selection to avoid unfavourable environments.