Misalignments between the orbital planes of planets and the equatorial planes of their host stars have been observed in our solar system, in transiting exoplanets, and in the orbital planes of debris discs. We present a mechanism that causes such a spin-orbit misalignment for a protoplanetary disc due to its movement through an ambient medium. Our physical explanation of the mechanism is based on the theoretical solutions to the Stark problem. We test this idea by performing self-consistent hydrodynamical simulations and simplified gravitational $N$-body simulations. The $N$-body model reduces the mechanism to the relevant physical processes. The hydrodynamical simulations show the mechanism in its full extent, including gas-dynamical and viscous processes in the disc which are not included in the theoretical framework. We find that a protoplanetary disc embedded in a flow changes its orientation as its angular momentum vector tends to align parallel to the relative velocity vector. Due to the force exerted by the flow, orbits in the disc become eccentric, which produces a net torque and consequentially changes the orbital inclination. The tilting of the disc causes it to contract. Apart from becoming lopsided, the gaseous disc also forms a spiral arm even if the inclination does not change substantially. The process is most effective at high velocities and observational signatures are therefore mostly expected in massive star-forming regions and around winds or supernova ejecta. Our $N$-body model indicates that the interaction with supernova ejecta is a viable explanation for the observed spin-orbit misalignment in our solar system.