In their natural habitat, bacteria are consumed by bacterivorous nematodes; however, they are not simply passive preys. Here we report a defensive mechanism used by certain bacteria to mobilize nematode-trapping fungi to kill nematodes. These bacteria release urea, which triggers a lifestyle switch in the fungus Arthrobotrys oligospora from saprophytic to nematodepredatory form; this predacious form is characterized by formation of specialized cellular structures or 'traps'. The bacteria significantly promote the elimination of nematodes by A. oligospora. Disruption of genes involved in urea transport and metabolism in A. oligospora abolishes the urea-induced trap formation. Furthermore, the urea metabolite ammonia functions as a signal molecule in the fungus to initiate the lifestyle switch to form trap structures. Our findings highlight the importance of multiple predator-prey interactions in prey defense mechanisms.