This cross-sectional study examined the prevalence and risk factors associated with gastrointestinal worm infections in sheep and goats in Ogbomoso, Nigeria. A total of 280 faecal samples were collected using a simple random sampling technique from 140 sheep and 140 goats. The samples were examined using simple floatation and formalin-ethyl acetate concentration techniques. The overall infection rate was 81.79%, with rates of 82.14% in sheep and 81.43% in goats. All three helminth classes were detected in both sheep and goats. A total of 11 helminth species were identified in sheep, mainly nematodes, with Haemonchus spp. (72.14%) being the most prevalent, and Paramphistomum spp. (0.71%) being the least prevalent. Thirteen helminths were identified in goats, where Haemonchus spp. (71.43%) had the highest occurrence, while Cooperia, Marshallagia, and Trichuris spp. (0.71%) had the lowest. Infection rates were not significantly influenced by sex, age, or breed (p > 0.05). This study confirms a high prevalence of a diverse range of gastrointestinal worms in sheep and goats in Ogbomoso, Nigeria.