Negative emotions and gut microbiota during pregnancy both bear significant public health implications. However, the relationship between them has not been fully elucidated. This study, utilizing data from a pregnancy cohort, employed metagenomic sequencing to elucidate the relationship between anxiety, depression, and gut microbiota’s diversity, composition, species, and functional pathways. Data from 87 subjects, spanning 225 time points across early, mid, and late pregnancy, were analyzed. The results revealed that anxiety and depression significantly corresponded to lower alpha diversity (including the Shannon entropy and the Simpson index). Anxiety and depression scores, along with categorical distinctions of anxiety/non-anxiety and depression/non-depression, were found to account for 0.723%, 0.731%, 0.651%, and 0.810% of the variance in gut-microbiota composition (p = 0.001), respectively. Increased anxiety was significantly positively associated with the abundance of Oscillibacter sp. KLE 1745, Oscillibacter sp. PEA192, Oscillibacter sp. KLE 1728, Oscillospiraceae bacterium VE202 24, and Treponema socranskii. A similar association was significantly noted for Oscillibacter sp. KLE 1745 with elevated depression scores. While EC.3.5.3.1: arginase appeared to be higher in the anxious group than in the non-anxious group, vitamin B12-related enzymes appeared to be lower in the depression group than in the non-depression group. The changes were found to be not statistically significant after post-multiple comparison adjustment.