Even though females currently outnumber males in higher education, they remain largely underrepresented in math-related fields of study, with no sign of improvement during the past decades. To better understand which students drive this underrepresentation, we use PISA 2012 data on 251,120 15-year-old students in 61 countries to analyse boys’ and girls’ educational intentions along the ability distribution on math assessment tests. We analyze the percentages of boys and girls intending to pursue math-related studies or careers as a function of math performance. First, we show that for both boys and girls, there is a positive and linear relation between the probability of intending to pursue math and math performance. Second, the positive relation is stronger among boys than among girls. In particular, the gender gap in student intentions to pursue math-related studies or careers is close to zero among the poorest performers in math and increases steadily with math performance. Third, as a consequence, the gender gap in math performance, to the detriment of girls, is larger among students intending to pursue math than in the general student population.