Abstract In gauge-Higgs unification (GHU), gauge symmetry is dynamically broken by an Aharonov–Bohm (AB) phase, θH, in the fifth dimension. We analyze SU(2) GHU with an SU(2) doublet fermion in the flat M4 × (S1/Z2) spacetime and in the Randall–Sundrum (RS) warped space. With orbifold boundary conditions the U(1) part of gauge symmetry remains unbroken at θH = 0 and π. The fermion multiplet has chiral zero modes at θH = 0, which become massive at θH = π. In other words, chiral fermions are transformed to vector-like fermions by the AB phase θH. The chiral anomaly at θH = 0 continuously varies as θH, and vanishes at θH = π. We demonstrate this intriguing phenomenon in the RS space in which no level crossing occurs in the mass spectrum and everything varies smoothly. The flat spacetime limit is singular as the anti-de Sitter curvature of the RS space diminishes, and reproduces the result in the flat spacetime. Anomalies appear for various combinations of Kaluza–Klein excitation modes of gauge fields as well. Although the magnitude of the anomalies depends on θH and the warp factor of the RS space, it does not depend on the bulk mass parameter of the fermion field controlling its mass and wave function at general θH.