Background: The aim of this study was to evaluate the association of oral health status and habits with the occurrence of ankylosing spondylitis (AS) in a nationwide population-based cohort in a longitudinal setting. Methods: A total of 2,415,963 individuals aged 40–79 years who underwent oral health examinations were included from the National Health Insurance Service-National Health Screening (NHIS-HEALS) cohort of Korea between 2003 and 2004. The occurrence of AS was analyzed according to the oral health status and oral hygiene habits. Results: Among 2,271,221 of the participants, AS occurred in 6366 (0.3%) participants over 16.7 years. The likelihood of AS was higher in participants who had periodontitis (hazard ratio [HR]: 1.33, 95% confidence interval [CI]: 1.20–1.46, p < 0.0001) and more missing teeth (HR: 1.68, 95% CI: 1.42–1.99, p < 0.0001). However, better oral hygiene habits such as frequent tooth brushing (HR: 0.77, 95% CI: 0.71–0.83, p < 0.0001) and a history of dental scaling within the last year (HR 0.88, 95% CI 0.82–0.95, p = 0.001) were associated with a lower occurrence of AS. Conclusions: Periodontitis and an increased number of missing teeth could be related to the occurrence of late-onset AS. Improved oral hygiene care may attenuate the likelihood of late-onset AS.