Species that depend on membership in social groups for survival exhibit changes in neuronal gene expression and behaviour when they face restricted social interactions or isolation1-3. Here we show that, across the lifespan of zebrafish (Danio rerio), social isolation specifically decreased the level of transcription of pth2, the gene that encodes the vertebrate-specific neuropeptide Pth2. However, 30 minutes of exposure to conspecifics was sufficient to initiate a significant rescue of pth2 transcript levels in previously isolated zebrafish. Transcription of pth2 exhibited bidirectional dynamics; following the acute isolation of socially reared fish, a rapid reduction in the levels of pth2 was observed. The expression of pth2 tracked not only the presence of other fish but also the density of the group. The sensory modality that controls the expression of pth2 was neither visual nor chemosensory in origin but instead was mechanical, induced by the movements of neighbouring fish. Chemical ablation of the mechanosensitive neuromast cells within the lateral line of fish prevented the rescue of pth2 levels that was induced by the social environment. In addition, mechanical perturbation of the water at frequencies similar to the movements of the zebrafish tail was sufficient to rescue the levels of pth2 in previously isolated fish. These data indicate a previously underappreciated role for the relatively unexplored neuropeptide Pth2 in both tracking and responding to the population density of the social environment of an animal.