We have conducted three-dimensional self-gravitating radiation hydrodynamical models of gas accretion on to high-mass cores (15–33 M⊕) over hundreds of orbits. Of these models, one case accretes more than a third of a Jupiter mass of gas, before eventually undergoing a hydrodynamic collapse. This collapse causes the density near the core to increase by more than an order of magnitude, and the outer envelope to evolve into a circumplanetary disc. A small reduction in the mass within the Hill radius (RH) accompanies this collapse as a shock propagates outwards. This collapse leads to a new hydrostatic equilibrium for the protoplanetary envelope, at which point 97 per cent of the mass contained within the Hill radius is within the inner 0.03RH which had previously contained less than 40 per cent. Following this collapse the protoplanet resumes accretion at its prior rate. The net flow of mass towards this dense protoplanet is predominantly from high latitudes, whilst at the outer edge of the circumplanetary disc there is net outflow of gas along the midplane. We also find a turnover of gas deep within the bound envelope that may be caused by the establishment of convection cells.