Waterfowl are considered to be natural reservoirs of the avian influenza virus (AIV). However, the dynamics of transmission and evolutionary patterns of AIV and its subtypes within duck farms in Bangladesh remain poorly documented. Hence, a cross-sectional study was conducted in nine districts of Bangladesh between 2019 and 2021, to determine the prevalence of AIV and its subtypes H5 and H9, as well as to identify risk factors and the phylodynamics of H5N1 clades circulating in domestic duck farms. The oropharyngeal and cloacal swab samples were tested for the AIV Matrix gene (M-gene) followed by H5, H7, and H9 subtypes using rRT-PCR. The exploratory analysis was performed to estimate AIV and its subtype prevalence in different production systems, and multivariable logistic regression model was used to identify the risk factors that influence AIV infection in ducks. Bayesian phylogenetic analysis was conducted to generate a maximum clade credibility (MCC) tree and the maximum likelihood method to determine the phylogenetic relationships of the H5N1 viruses isolated from ducks. AIV was detected in 40% (95% CI: 33.0–48.1) of the duck farms. The prevalence of AIV was highest in nomadic ducks (39.8%; 95% CI: 32.9–47.1), followed by commercial ducks (24.6%; 95% CI: 14.5–37.3) and backyard ducks (14.4%; 95% CI: 10.5–19.2). The H5 prevalence was also highest in nomadic ducks (19.4%; 95% CI: 14.0–25.7). The multivariable logistic regression model revealed that ducks from nomadic farms (AOR: 2.4; 95% CI: 1.45–3.93), juvenile (AOR: 2.2; 95% CI: 1.37–3.61), and sick ducks (AOR: 11.59; 95% CI: 4.82–32.44) had a higher risk of AIV. Similarly, the likelihood of H5 detection was higher in sick ducks (AOR: 40.8; 95% CI: 16.3–115.3). Bayesian phylogenetic analysis revealed that H5N1 viruses in ducks belong to two distinct clades, 2.3.2.1a, and 2.3.4.4b. The clade 2.3.2.1a (reassorted) has been evolving silently since 2015 and forming at least nine subgroups based on >90% posterior probability. Notably, clade 2.3.4.4b was introduced in ducks in Bangladesh by the end of the year 2020, which was genetically similar to viruses detected in wild birds in Japan, China, and Africa, indicating migration-associated transmission of an emerging panzootic clade. We recommend continuing AIV surveillance in the duck production system and preventing the intermingling of domestic ducks with migratory waterfowl in wetlands.