Recent discoveries of strongly misaligned transiting exoplanets pose a challenge to the established planet formation theory which assumes planetary systems to form and evolve in isolation. However, the fact that the majority of stars actually do form in star clusters raises the question how isolated forming planetary systems really are. Besides radiative and tidal forces, dense gas aggregates in star-forming regions are potential sources for perturbations to protoplanetary discs or systems. Here we show that subsequent capture of gas from large extended accretion envelopes on to a passing star with a typical circumstellar disc can tilt the disc plane to retrograde orientation, naturally explaining the formation of strongly inclined planetar...