Sex differences occur in most species and affect a variety of biological traits including morphology, behavior, and life history. The nematode Caenorhabditis elegans exists as a population of self-fertile hermaphrodites with occasional males, which differ anatomically and behaviorally from hermaphrodites. Here we show that male C. elegans also differ from hermaphrodites in their susceptibility to a fungal pathogen, Cryptococcus neoformans. Wild-type males show greater resistance than hermaphrodite animals to killing by this pathogen and this resistance can be induced in hermaphrodite animals by inappropriate activation of the male sex-determination pathway. Resistance is molecularly determined, rather than resulting from behavioral changes or reproductive differences, and requires the activity of the stress-response transcription factor DAF-16. Finally, we demonstrate that resistance to C. neoformans correlates broadly with longevity within the Caenorhabditis genus. Our results hint at an overlap between the pathways controlling immunity and longevity and raise the possibility that differential regulation of these pathways may contribute to sex-dependent and species-dependent variation.