Humans have colonized and adapted to extremely diverse environments, and the genetic basis of some such adaptations, for example to high altitude, is understood. In some cases, local or regional variation in selection pressure could also cause behavioural adaptations. Numerous genes influence behaviour, such as alleles at the dopamine receptor locus D4 (DRD4), which are associated with attitude toward risk in experimental settings. We demonstrate genetic differentiation for this gene, but not for five unlinked microsatellite loci, between high- and low risk environments around Mount Merapi, an active volcano in Java, Indonesia. Using a behavioural experiment, we further show that people inhabiting the high risk environment are significantly more risk averse. We provide evidence of a genetic basis for this difference, showing that heterozygotes at the DRD4 locus are more risk averse than either homozygotes. In the high risk environment, allele frequencies are equilibrated, generating a high frequency of heterozygotes. Thus it appears that overdominance (i.e. selective advantage of heterozygotes) generates negative frequency dependent selection, favouring the rarer allele at this locus. Our results therefore provide evidence for adaptation to a marginal habitat through the selection of a neurocognitive trait with a genetic basis.