Radio observations at metre-centimetre wavelengths shed light on the nature of the emission of HII regions. Usually this category of objects is dominated by thermal radiation produced by ionised hydrogen, namely protons and electrons. However, a number of observational studies have revealed the existence of HII regions with a mixture of thermal and non-thermal radiation. The latter represents a clue as to the presence of relativistic electrons. However, neither the interstellar cosmic-ray electron flux nor the flux of secondary electrons, produced by primary cosmic rays through ionisation processes, is high enough to explain the observed flux densities. We investigate the possibility of accelerating local thermal electrons up to relativistic energies in HII region shocks. We assumed that relativistic electrons can be accelerated through the first-order Fermi acceleration mechanism and we estimated the emerging electron fluxes, the corresponding flux densities, and the spectral indexes. We find flux densities of the same order of magnitude of those observed. In particular, we applied our model to the deep south (DS) region of Sagittarius B2 and we succeeded in reproducing the observed flux densities with an accuracy of less than 20% as well as the spectral indexes. The model also gives constraints on magnetic field strength ($0.3-4$ mG), density ($1-9times10^4$ cm$^{-3}$), and flow velocity in the shock reference frame ($33-50$ km s$^{-1}$) expected in DS. We suggest a mechanism able to accelerate thermal electrons inside HII regions through the first-order Fermi acceleration. The existence of a local source of relativistic electrons can explain the origin of both the observed non-thermal emission and the corresponding spectral indexes.