Objective To investigate the characteristics of gut microbiome and their associations with lymphocyte subsets and disease activity in patients with ankylosing spondylitis (AS). Methods This study was a retrospective analysis. The subjects of the study were AS patients who were hospitalized in the Second Hospital of Shanxi Medical University from December 2019 to June 2020, as well as gender- and age-matched healthy controls (HCs). The fecal samples were collected, and the V3-V4 variable regions of 16S rRNA gene of gut microbiome were sequenced for bioinformatics analysis. Peripheral venous blood was collected from AS patients to determine peripheral blood lymphocyte subsets and disease activity indicators. Spearman correlation test was used to analyze the correlations between the relative abundances of gut microbiota and peripheral blood lymphocyte subsets as well as disease activity in AS patients. Results A total of 62 AS patients (11 with low disease activity, 26 with high disease activity, and 25 with extremely high disease activity) and 62 healthy people who met the inclusion and exclusion criteria were enrolled. As for α-diversity, ACE and Chao1 indices were lower in AS than in HCs(P < 0.05). Bray curtis distance-based β-diversity analysis revealed significant difference in the microbial community between AS and HCs (P < 0.01). As for the composition of the gut microbiome, Firmicutes, Bacteroidetes, and Proteobacteria were the dominant phyla in the gut microbiota of both groups, but there were differences in the abundance of various bacteria at the phylum and genus levels. In Stamp analysis, fecal microbial communities in AS differed significantly from those in HCs, which were characterized by higher abundances of phylum Proteobacteria and Patescibacteria(all P < 0.05) and a lower abundance of phylum Firmicutes and Fusobacteriota (all P < 0.05). At the genus level, the abundances of Escherichia-Shigella, Klebsiella and Enterococcus were increased while those of Prevotella and Faecalibacterium were decreased in AS patients compared to HCs(all P < 0.05). Spearman correlation analysis showed that the relative abundances of Faecalibacterium, Ruminococcus and Klebsiella in AS patients were significantly positively correlated with disease activity or its related indicators(all P < 0.05). There were positive correlations between Agathobacter and T cell (r=0.302, P=0.017), CD4+T cell (r=0.310, P=0.014), B cell (r=0.292, P=0.021), Th2 cell (r=0.429, P < 0.001), Th17 cell (r=0.288, P=0.023), Streptococcus and B cell (r=0.270, P=0.034), Prevotella and Th1 cell (r=0.279, P=0.028), Th17 cell (r=0.262, P=0.040), CAG-352 and Th1 cell (r=0.283, P=0.030). There were negative correlations between Escherichia-Shigella and Th2 cell(r=-0.261, P=0.040), other Enterobacteriaceae and CD4+T cell (r=-0.255, P=0.046). Conclusions The diversity of gut microbiota is reduced in AS patients. The abundance of pathogenic bacteria in AS patients is increased, which is correlated with changes in peripheral blood lymphocyte subsets and disease activity. Dysbiosis may be involved in the occurrence and development of AS.