This study was conducted in four districts (Malakand, Swat, Bajaur and Shangla) of Northern Pakistan to investigate the prevalence, associated risk factors and phylogenetic analyses of Theileria and Anaplasma species in small ruminants. A total of 800 blood samples, 200 from each district, were collected from apparently healthy animals. PCR assays were performed using generic primers for Anaplasma spp. and Theileria spp. as well as species specific primers for A. ovis and T. ovis. Overall infection prevalence was 361/800 (45.1%). Theileria spp. infection prevalence (187/800, 23.3%) was higher than Anaplasma spp. (174/800, 21.7%). Amplified partial 18S rRNA genes were sequenced and enrolled animals were found to be infected by T. ovis (115/800, 14.3%), and at least two more Theileria species (72/800, 9%) were present (T. lestoquardi and T. annulata). All blood samples that were found to be positive for Anaplasma spp. were also positive for A. ovis. Infection prevalence was higher in sheep (227/361, 28.3%) compared to goats (134/361, 16.6%) (p < 0.005). Univariable analysis of risk factors showed that host, age, grazing system and acaricide treatment were significant determinants (p < 0.05) for both Theileria and Anaplasma infections. Multivariable analysis revealed that host, sex, age, tick infestation and grazing system were significant risk factors (p < 0.005) for both pathogens. Phylogenetic analysis revealed variants among the A. ovis and T. annulata samples analysed, indicating that different genotypes are circulating in the field while T. ovis presented the same genotype for the samples analysed.