This study aimed to evaluate the association between tumor necrosis factor-α inhibitor (TNFi) therapy and cardiovascular (CV) outcomes, as well as all-cause mortality, in patients with ankylosing spondylitis (AS). This retrospective cohort study included 24,986 patients newly diagnosed with AS between 2010-2019 without a history of CV diseases, using data from the Korean National Health Insurance Service. CV events were observed through the end of 2021. After exposure density sampling (1:1), we investigated the association among use of TNFi, duration of TNFi use, and risk of the composite CV outcome (ischemic stroke, heart failure, ischemic heart disease, or CV death) and all-cause mortality. Overall, TNFi users (N = 8,650) and non-users (N = 8,580) had a comparable risk of the composite CV outcome. However, prolonged TNFi use (≥ 1 year) was associated with a significantly lower risk of the composite CV outcome [adjusted hazard ratio (aHR): 0.72, 95% CI: 0.55-0.93, p = 0.012] and all-cause mortality (aHR: 0.37, 95% CI: 0.21-0.66, p < 0.001) compared to discontinued TNFi use (< 1 year), with adjustments made for age, sex, disease duration, hypertension, diabetes, hyperlipidemia, chronic kidney disease, non-steroidal anti-inflammatory drug (NSAID) use, body mass index (BMI), and smoking status. TNFi therapy did not reduce CV events in AS patients. However, long-term TNFi therapy is likely to be beneficial in reducing CV events and all-cause mortality compared to discontinuing TNFi therapy in patients with AS.