Massive galaxies in the young Universe, ten billion years ago, formed stars at surprising intensities. Although this is commonly attributed to violent mergers, the properties of many of these galaxies are incompatible with such events, showing gas-rich, clumpy, extended rotating disks not dominated by spheroids. Cosmological simulations and clustering theory are used to explore how these galaxies acquired their gas. Here we report that they are 'stream-fed galaxies', formed from steady, narrow, cold gas streams that penetrate the shock-heated media of massive dark matter haloes. A comparison with the observed abundance of star-forming galaxies implies that most of the input gas must rapidly convert to stars. One-third of the stream mass is in gas clumps leading to mergers of mass ratio greater than 1:10, and the rest is in smoother flows. With a merger duty cycle of 0.1, three-quarters of the galaxies forming stars at a given rate are fed by smooth streams. The rarer, submillimetre galaxies that form stars even more intensely are largely merger-induced starbursts. Unlike destructive mergers, the streams are likely to keep the rotating disk configuration intact, although turbulent and broken into giant star-forming clumps that merge into a central spheroid. This stream-driven scenario for the formation of discs and spheroids is an alternative to the merger picture.