Anterior-posterior patterning in insects, vertebrates and nematodes involves members of conserved Antennapedia-class homeobox gene clusters (HOM-C) that are thought to give specific body regions their identities. The effects of these genes on region-specific body structures have been described extensively, particularly in Drosophila, but little is known about how HOM-C genes affect the behaviours of cells that migrate into their domains of function. In Caenorhabditis elegans, the Antennapedia-like HOM-C gene mab-5 not only specifies postembryonic fates of cells in a posterior body region, but also influences the migration of mesodermal and neural cells that move through this region. Here we show that as one neuroblast migrates into this posterior region, it switches on mab-5 gene expression; mab-5 then acts as a developmental switch to control the migratory behaviour of the neuroblast descendants. HOM-C genes can therefore not only direct region-specific patterns of cell division and differentiation, but can also act within migrating cells to programme region-specific migratory behaviour.