This study aimed to investigate the relationship among smoking, TNF-α-blocker therapy, and the dynamic changes in gut microbiota in patients with ankylosing spondylitis (AS). Using a 16S rRNA sequence, 98 fecal samples of 20 AS patients collected after 0, 1, 3 and 6 months of anti-TNF-α treatment and from 20 matched health controls were examined. The variation in composition, abundance, and diversity of gut microbiota was analyzed. The dynamic effects of smoking and treatment on gut microbiota and therapeutic efficacy in AS patients were studied. The increased relative abundance of microbiota in AS nonsmokers was g_Comamonas and g_Desulfovibrio, while that in AS smokers was g_Actinomyces, g_Collinsella, g_Lachnospiraceae_UCG-008, and g_Paraprevotella. The relative abundance of gut microbiota showed dynamic variation. The improvement rate of ASDAS in AS nonsmokers was higher than that in AS smokers (2.297 vs 1.736) after anti-TNF-α treatment. The β-diversity of gut microbiota in AS smokers was lower than that in AS nonsmokers and improved with treatment. Both smoking and TNF-α-blocker had significant effects on the composition, relative abundance, and diversity of gut microbiota in AS patients. The AS smokers characteristically shared g_Collinsella and g_Dorea. The relative abundance of gut microbiota revealed high variability and was in dynamic fluctuation during treatment. The response of gut microbiota to anti-TNF-α treatment was found to be heterogeneous and selective. AS nonsmokers showed a greater improvement rate of ASDAS-CRP with treatment than AS smokers did. The AS smokers showed a lower β-diversity of gut microbiota, and improved after treatment.