The physical processes of the gamma-ray emission and particle acceleration during the prompt phase in gamma ray bursts (GRBs) are still unsettled. In order to perform an unambiguous physical modelling of observations, a clear identification of the emission mechanism is needed. An instance of a clear identification is the synchrotron emission during the very strong flare in GRB160821A, that occurs during the prompt phase at 135 s. Here we show that the distribution of the radiating electrons in this flare is initially very narrow, but later develops a power-law tail of accelerated electrons. We thus identify for the first time the onset of particle acceleration in a GRB jet. The flare is consistent with a late energy release from the central engine causing an external-shock as it encounters a preexisting ring nebula of a progenitor Wolf-Rayet star. Relativistic forward and reverse shocks develop, leading to two distinct emission zones with similar properties. The particle acceleration only occurs in the forward shock, moving into the dense nebula matter. Here, the magnetisation also decreases below the critical value, which allows for Fermi acceleration to operate. Using this fact, we find a bulk Lorentz factor of 420 < ∼ Γ < ∼ 770, and an emission radius of R ∼ 10 18 cm, indicating a tenuous gas of the immediate circumburst surrounding. The observation of the onset of particle acceleration thus gives new and independent constraints on the properties of the flow as well as on theories of particle acceleration in collisionless astrophysical shocks.