Transition to uniform turbulence in cylindrical pipe flow occurs experimentally via the spatial expansion of isolated coherent structures called ‘slugs’, triggered by localized finite-amplitude disturbances. We study this process numerically by examining the preferred route in phase space through which a critical disturbance initiates a ‘slug’. This entails first identifying the relative attractor – ‘edge state’ – on the laminar–turbulent boundary in a long pipe and then studying the dynamics along its low-dimensional unstable manifold, leading to the turbulent state. Even though the fully turbulent state delocalizes at Re ≈ 2300, the edge state is found to be localized over the range Re = 2000–6000, and progressively reduces in both energy and spatial extent as Re is increased. A key process in the genesis of a slug is found to be vortex shedding via a Kelvin–Helmholtz mechanism from wall-attached shear layers quickly formed at the edge state's upstream boundary. Whether these shedded vortices travel on average faster or slower downstream than the developing turbulence determines whether a puff or a slug (respectively) is formed. This observation suggests that slugs are out-of-equilibrium puffs which therefore do not co-exist with stable puffs.