Parathyroid hormone (PTH) interacts with components of the gut microbiota to exert its bone-regulating effects. This study aimed to investigate the gut microbial composition in patients with primary hyperparathyroidism (PHPT). Nine patients with PHPT and nine age-sex and body mass index-matched healthy controls were included. Gut microbial composition was assessed using 16S rRNA gene amplicon sequencing in both groups at baseline and one month after parathyroidectomy in the PHPT group. Data were imported into QIIME-2 and both QIIME-2 and R packages were used for microbiome analysis. Alpha and beta diversity were similar between the groups and remained unchanged after parathyroidectomy. The relative abundance of Subdoligranulum was significantly higher, whereas Ruminococcus, Alloprevotella, Phascolarctobacterium and Clostridium sensu stricto_1 were significantly lower in PHPT than in controls (p<0.001). After parathyroidectomy, the relative abundance of Subdoligranulum decreased, Ruminococcus and Alloprevotella increased (p<0.001). The PHPT group had lower total femoral and lumbar bone mineral density (BMD) than the controls (p<0.05). At baseline, Alloprevotella abundance was positively correlated with serum phosphorus and Subdoligranulum was positively correlated with total lumbar BMD. Clostridium sensu stricto_1 was negatively correlated with serum calcium and positively correlated with femoral neck BMD. Postoperatively, Alloprevotella was positively correlated with baseline serum phosphorus, and Phascolarctobacterium was positively correlated with distal radius BMD. This study demonstrated that the diversity of the gut microbiome was altered, possibly in response to electrolyte changes in PHPT, both before and after parathyroidectomy.