In many organisms, population-density sensing and sexual attraction rely on small-molecule-based signalling systems. In the nematode Caenorhabditis elegans, population density is monitored through specific glycosides of the dideoxysugar ascarylose (the 'ascarosides') that promote entry into an alternative larval stage, the non-feeding and highly persistent dauer stage. In addition, adult C. elegans males are attracted to hermaphrodites by a previously unidentified small-molecule signal. Here we show, by means of combinatorial activity-guided fractionation of the C. elegans metabolome, that the mating signal consists of a synergistic blend of three dauer-inducing ascarosides, which we call ascr#2, ascr#3 and ascr#4. This blend of ascarosides acts as a potent male attractant at very low concentrations, whereas at the higher concentrations required for dauer formation the compounds no longer attract males and instead deter hermaphrodites. The ascarosides ascr#2 and ascr#3 carry different, but overlapping, information, as ascr#3 is more potent as a male attractant than ascr#2, whereas ascr#2 is slightly more potent than ascr#3 in promoting dauer formation. We demonstrate that ascr#2, ascr#3 and ascr#4 are strongly synergistic, and that two types of neuron, the amphid single-ciliated sensory neuron type K (ASK) and the male-specific cephalic companion neuron (CEM), are required for male attraction by ascr#3. On the basis of these results, male attraction and dauer formation in C. elegans appear as alternative behavioural responses to a common set of signalling molecules. The ascaroside signalling system thus connects reproductive and developmental pathways and represents a unique example of structure- and concentration-dependent differential activity of signalling molecules.