Goal 4 of the United Nations Sustainable Development Goals emphasizes ensuring inclusive and equitable quality education to achieve sustainability. It is well known that gifted mathematics education is crucial, but teachers for gifted mathematics education are extremely scarce. The promotion of sustainability in gifted mathematics education on a large scale is an important issue to ensure equity and quality in education. Mathematical competitions have always been an important method for gifted education and have received widespread attention from students and parents. Many high school students prepare for these competitions through extracurricular gifted mathematics tutoring. With the advancement of science and technology and the outbreak of the COVID-19 pandemic in 2020, many tutoring courses have gradually turned to online courses. Online gifted mathematics education has become a model for developing gifted education. In this study, we conducted an in-depth analysis of the learning patterns, grades, and family backgrounds of students participating in mathematics competitions in 10 key high schools in Liaoning Province from 2018 to 2024. The research results are as follows: (1) Before the COVID-19 pandemic, extracurricular gifted mathematics education primarily consisted of offline courses. During the COVID-19 pandemic, online learning resources developed rapidly and became prevalent, while offline education decreased. (2) Students from high-income families preferred offline courses when participating in extracurricular gifted education tutoring for mathematics. In contrast, students from middle- and low-income families were more inclined to choose online courses. Household registration and the place of residence had a weak correlation with the time spent participating in online gifted mathematics education. Among the influencing factors, material resources such as computers, smartphones, and broadband internet had a significant mediating effect. (3) With the advent of online education, the correlation between mathematics competition achievements and family income significantly decreased. However, students from rural families face challenges in accessing online education due to a lack of material resources consequent to the COVID-19 pandemic, resulting in lower mathematics competition achievements. The results show that online gifted education in mathematics breaks through the limitations of time, space, and resources; solves the problem of scarce teaching staff; and helps promote a comprehensive strategy for sustainable development in gifted education. At the same time, issues such as the digital divide, insufficient hardware, and limited internet access still need to be addressed.