The outer areas of Jupiter and Saturn have multiple zonal winds, reaching the high latitudes, that penetrate deep into the planets' interiors, as suggested by gravity measurements. These characteristics are finally replicable in numerical simulations by including both a shallow stably stratified layer, below a convecting envelope, and increasing electrical conductivity. A dipolar magnetic field, assumed to be generated by a dynamo below our model, is imposed. We find that the winds' depth into the stratified layer depends on the local product of the squared magnetic field strength and electrical conductivity. The key for the drop-off of the zonal winds is a meridional circulation which perturbs the density structure in the stable layer. In the stable region its dynamics is governed by a balance between Coriolis and electromagnetic forces. Our models suggest that a stable layer extending into weakly conducting regions could account for the observed deep zonal wind structures.