Wild isolates of the nematode Caenorhabditis elegans perform social behaviours, namely clumping and bordering, to avoid hyperoxia under laboratory conditions. In contrast, the laboratory reference strain N2 has acquired a solitary behaviour in the laboratory, related to a gain-of-function variant in the neuropeptide Y-like receptor NPR-1. Here, we study the evolution and natural variation of clumping and bordering behaviours in Pristionchus pacificus nematodes in a natural context, using strains collected from 22 to 2400 metres above sea level on La Réunion Island. Through the analysis of 106 wild isolates, we show that the majority of strains display a solitary behaviour similar to C. elegans N2, whereas social behaviours are predominantly seen in strains that inhabit high-altitude locations. We show experimentally that P. pacificus social strains perform clumping and bordering to avoid hyperoxic conditions in the laboratory, suggesting that social strains may have adapted to or evolved a preference for the lower relative oxygen levels available at high altitude in nature. In contrast to C. elegans, clumping and bordering in P. pacificus do not correlate with locomotive behaviours in response to changes in oxygen conditions. Furthermore, QTL analysis indicates clumping and bordering to represent complex quantitative traits. Thus, clumping and bordering behaviours represent an example of phenotypic convergence with a different evolutionary history and distinct genetic control in both nematode species.