We present results from three-dimensional, self-gravitating radiation hydrodynamical models of gas accretion by planetary cores. In some cases, the accretion flow is resolved down to the surface of the solid core - the first time such simulations have been performed. We investigate the dependence of the gas accretion rate upon the planetary core mass, and the surface density and opacity of the encompassing protoplanetary disc. Accretion of planetesimals is neglected. We find that high-mass protoplanets are surrounded by thick circumplanetary discs during their gas accretion phase but, contrary to locally isothermal calculations, discs do not form around accreting protoplanets with masses less than or similar to 50M(circle plus). when radiation hydrodynamical simulations are performed, even if the grain opacity is reduced from interstellar values by a factor of 100. We find that the opacity of the gas plays a large role in determining the accretion rates for low-mass planetary cores. For example, reducing the opacities from interstellar values by a factor of 100 leads to roughly an order of magnitude increase in the accretion rates for 10-20M(circle plus). protoplanets. The dependence on opacity becomes less important in determining the accretion rate for more massive cores where gravity dominates the effects of thermal support and the protoplanet is essentially accreting at the runaway rate. Increasing the core mass from 10 to 100 M(circle plus) increases the accretion rate by a factor of approximate to 50 for interstellar opacities. Beyond similar to 100 M(circle plus), the ability of the protoplanetary disc to supply material to the accreting protoplanet limits the accretion rate, independent of the opacity. Finally, for low-mass planetary cores (less than or similar to 20M(circle plus)),we obtain accretion rates that are in agreement with previous one-dimensional quasi-static models. This indicates that three-dimensional hydrodynamical effects may not significantly alter the gas accretion time-scales that have been obtained from quasi-static models.