Controlling foodborne pathogens in buffalo milk is crucial for ensuring food safety. This study estimated the prevalence of nine target genes representing seven critical foodborne bacteria in milk and milk products, and identified factors associated with their presence in buffalo milk chain nodes in Bangladesh. One hundred and forty-three milk samples from bulk tank milk (n = 34), middlemen (n = 37), milk collection centers (n = 37), and milk product shops (n = 35) were collected and analyzed using RT-PCR. Escherichia (E.) coli, represented through yccT genes, was the most prevalent throughout the milk chain (81–97%). Chi-squared tests were performed to identify the potential risk factors associated with the presence of foodborne bacteria encoded for different genes. At the middleman level, the prevalence of E. coli was associated with the Mymensingh, Noakhali, and Bhola districts (P = 0.01). The prevalence of Listeria monocytogenes, represented through inlA genes, and Yersinia (Y.) enterocolitica, represented through yst genes, were the highest at the farm level (65–79%). The prevalence of both bacteria in bulk milk was associated with the Noakhali and Bhola districts (P < 0.05). The prevalence of Y. enterocolitica in bulk milk was also associated with late autumn and spring (P = 0.01) and was higher in buffalo-cow mixed milk than in pure buffalo milk at the milk collection center level (P < 0.01). The gene stx2 encoding for Shiga toxin-producing (STEC) E. coli was detected in 74% of the milk products. At the middleman level, the prevalence of STEC E. coli was associated with the use of cloths or tissues when drying milk containers (P = 0.01). Salmonella enterica, represented through the presence of invA gene, was most commonly detected (14%) at the milk collection center. The use of plastic milk containers was associated with a higher prevalence of Staphylococcus aureus, represented through htrA genes, at milk product shops (P < 0.05). These results suggest that raw milk consumers in Bangladesh are at risk if they purchase and consume unpasteurized milk.