We propose a modification of the Hybrid Monte Carlo (HMC) algorithm that overcomes the topological freezing of a two-dimensional U(1) gauge theory with and without fermion content. This algorithm includes reversible jumps between topological sectors - winding steps - combined with standard HMC steps. The full algorithm is referred to as winding HMC (wHMC), and it shows an improved behaviour of the autocorrelation time towards the continuum limit. We find excellent agreement between the wHMC estimates of the plaquette and topological susceptibility and the analytical predictions in the U(1) pure gauge theory, which are known even at finite β . We also study the expectation values in fixed topological sectors using both HMC and wHMC, with and without fermions. Even when topology is frozen in HMC - leading to significant deviations in topological as well as non-topological quantities - the two algorithms agree on the fixed-topology averages. Finally, we briefly compare the wHMC algorithm results to those obtained with master-field simulations of size L ∼8 ×103.