The early diagnosis and treatment of ectopic pregnancy (EP) remains a major challenge. Despite a known link between vaginal microbiota and female reproductive health, few studies have focused on the association between vaginal microbiota and pregnancy location. This nested case-control study aimed to characterize the vaginal microbiota in tubal pregnancy (TP) among symptomatic women in early pregnancy. Women with symptomatic early pregnancy of unknown location (PUL) were included in this study. 16S rDNA gene sequencing was performed to assess vaginal microbial diversity and relative abundance. Machine learning and multivariate logistic regression were also used to evaluate the association between Gardnerella and TP. The results indicate that the vaginal microbiome in TP was more diverse (Shannon, p < 0.05) and was different in composition to that of women with intrauterine pregnancy (IUP) (weighted Unifrac, R = 0.08, p = 0.01). The genus Gardnerella was significantly enriched in TP. The XGBoost analysis was able to classify Gardnerella-induced TP more reliably (AUC = 0.621). Moreover, after adjusting potential confounders, our results indicate a robust association between Gardnerella and TP (as a continuous variable, adjusted OR: 12.0, 95% CI: 2.1–67.4, p < 0.01; as a categorical variable (≥0.85%), and adjusted OR: 4.2, 95% CI: 2.0–8.8, p < 0.01). In conclusion, we found that higher virginal Gardnerella levels were associated with TP in women with symptomatic early pregnancy.