Spatial ability predicts performance in mathematics and eventual expertise in science, technology and engineering. Spatial skills have also been shown to rely on neuronal networks partially shared with mathematics. Understanding the nature of this association can inform educational practices and intervention for mathematical underperformance. Using data on two aspects of spatial ability and three domains of mathematical ability from 4174 pairs of 12-year-old twins, we examined the relative genetic and environmental contributions to variation in spatial ability and to its relationship with different aspects of mathematics. Environmental effects explained most of the variation in spatial ability (~70%) and in mathematical ability (~60%) at this age, and the effects were the same for boys and girls. Genetic factors explained about 60% of the observed relationship between spatial ability and mathematics, with a substantial portion of the relationship explained by common environmental influences (26% and 14% by shared and non-shared environments respectively). These findings call for further research aimed at identifying specific environmental mediators of the spatial-mathematics relationship.