Using data from the 2012 PISA across 56 countries, this study examines the link between societal gender inequalities and the gender test score gap in mathematics. We employ a novel two-stage empirical strategy in which the first stage involves decomposing the gender mathematics gap into a part that is explained by gender differences in observable characteristics and a part that remains unexplained. We use a semiparametric Oaxaca- Blinder (OB) decomposition to analyze the gap in each country individually. In the second stage, we investigate whether the decomposition components of the gap are systematically related to country-level gender inequality measures. The results indicate that the gap is not statistically significantly associated with the indicators of gender inequality, but the unexplained part of the gap is. In more gender-equal countries, the unexplained part of the gap favoring boys appears smaller. Moreover, we find that the relationship between the unexplained part of the gap and the societal gender inequality varies within the test score distribution, and tends to become less pronounced at the upper end of the distribution.