Solar flares, driven by prompt release of free magnetic energy in the solar corona1,2, are known to accelerate a substantial portion (ten per cent or more)3,4 of available electrons to high energies. Hard X-rays, produced by high-energy electrons accelerated in the flare5, require a high ambient density for their detection. This restricts the observed volume to denser regions that do not necessarily sample the entire volume of accelerated electrons6. Here we report evolving spatially resolved distributions of thermal and non-thermal electrons in a solar flare derived from microwave observations that show the true extent of the acceleration region. These distributions show a volume filled with only (or almost only) non-thermal electrons while being depleted of the thermal plasma, implying that all electrons have experienced a prominent acceleration there. This volume is isolated from a surrounding, more typical flare plasma of mainly thermal particles with a smaller proportion of non-thermal electrons. This highly efficient acceleration happens in the same volume in which the free magnetic energy is being released2.