The nematode Caenorhabditis elegans has in recent years been proven to be a powerful in vivo model for testing antimicrobial compounds. We report here that the alkaloid compound Harmane (2-methyl-β-carboline) increases the lifespan of nematodes infected with a human pathogen, the Shiga toxin-producing Escherichia coli O157:H7 strain EDL933 and several other bacterial pathogens. This was shown to be unrelated to the weak antibiotic effect of Harmane. Using GFP-expressing E. coli EDL933, we showed that Harmane does not lower the colonization burden in the nematodes. We also found that the expression of the putative immune effector gene F35E12.5 was up-regulated in response to Harmane treatment. This indicates that Harmane stimulates the innate immune response of the nematode; thereby increasing its lifespan during bacterial infection. Expression of F35E12.5 is predominantly regulated through the p38 MAPK pathway; however, intriguingly the lifespan extension resulting from Harmane was higher in p38 MAPK-deficient nematodes. This indicates that Harmane has a complex effect on the innate immune system of C. elegans. Harmane could therefore be a useful tool in the further research into C. elegans immunity. Since the innate immunity of C. elegans has a high degree of evolutionary conservation, drugs such as Harmane could also be possible alternatives to classic antibiotics. The C. elegans model could prove to be useful for selection and development of such drugs.