L-H transition features are reproduced using three-dimensional first-principles plasma edge turbulence simulations. A transport barrier is observed to form spontaneously above a threshold of the input power. The physical mechanism relies on the coupling between the equilibrium pressure gradient and the poloidal flow, through both the radial force balance and the neoclassical friction. Accounting for the actual radial profile and time evolution of the latter is key to the barrier formation. It is found that neoclassical friction acts as an energy source for the flow, which largely overcomes the sink due to the turbulent Reynolds stress during the whole barrier lifetime. Importantly, experimentally reported dynamical features are recovered during the formation and lifetime of the barrier. This includes dithering of the radial electric field, which is reminiscent of experimentally observed limit-cycle oscillations and quasi-periodic relaxation oscillations showing similarities with type-III ELMs. These rich dynamics emerge from interplay between turbulence, turbulence-driven flows and the equilibrium flow governed by force balance.