How chaperones, insertases and translocases facilitate insertion and folding of complex cytoplasmic proteins into cellular membranes is not fully understood. Here, we utilize single-molecule force spectroscopy to observe YidC, a transmembrane chaperone/insertase, sculpting the folding trajectory of the polytopic α-helical membrane protein lactose permease (LacY). In the absence of YidC, unfolded LacY inserts individual structural segments into the membrane; however, misfolding dominates the process so that folding cannot be completed. YidC prevents LacY from misfolding by stabilizing the unfolded state from which LacY inserts structural segments stepwise into the membrane until folding is completed. During stepwise insertion, YidC and membrane together stabilize the transient folds. Remarkably, the order of insertion of structural segments is stochastic, thereby indicating that LacY can fold along variable pathways towards the native structure. Since YidC is essential in membrane protein biogenesis and LacY a paradigm for the major facilitator superfamily, our observations have general relevance.