Data from the Swift satellite have enabled us for the first time to provide a complete picture of the gamma-ray (γ-ray) burst emission mechanism and its relationship with the early afterglow emissions. We show that γ-ray photons for two bursts, 050126 and 050219A, for which we have carried out detailed analysis were produced as a result of the synchrotron self-Compton process in the material ejected in the explosion when it was heated to a mildly relativistic temperature at a distance from the centre of explosion of order the deceleration radius. Both of these bursts exhibit rapidly declining early X-ray afterglow light curves; this emission is from the same source that produced the γ-ray burst. The technique that we exploit to determine this is very general and makes no assumption about any particular model for γ-ray generation except that the basic radiation mechanism is some combination of synchrotron and inverse Compton processes in a relativistic outflow. For GRB 050219A we can rule out the possibility that energy from the explosion is carried outward by magnetic fields, and that the dissipation of this field produced the γ-ray burst.