Horizontal gene transfer involves the non-sexual interspecific transmission of genetic material. Even if they are initially functional, horizontally transferred genes are expected to deteriorate into non-expressed pseudogenes, unless they become adaptively relevant in the recipient organism. However, little is known about the distributions of natural transgenes within wild species or the adaptive significance of natural transgenes within wild populations. Here, we examine the distribution of a natural plant-to-plant nuclear transgene in relation to environmental variation within a wild population. Festuca ovina is polymorphic for an extra (second) expressed copy of the nuclear gene (PgiC) encoding cytosolic phosphoglucose isomerase, with the extra PgiC locus having been acquired horizontally from the distantly related grass genus Poa. We investigated variation at PgiC in samples of F. ovina from a fine-scale, repeating patchwork of grassland microhabitats, replicated within spatially separated sites. Even after accounting for spatial effects, the distributions of F. ovina individuals carrying the additional PgiC locus, and one of the enzyme products encoded by the locus, are significantly associated with fine-scale habitat variation. Our results suggest that the PgiC transgene contributes, together with the unlinked 'native' PgiC locus, to local adaptation to a fine-scale mosaic of edaphic and biotic grassland microhabitats.