Growing the gas-giant planets by the gradual accumulation of pebbles