(This is all for shuttle, not SLS)
Running the engine out of propellant was a Big Bad Thing. There were sensors in the External Tank (for hydrogen) and in the orbiter feedlines (for oxygen) that would trigger a shutdown if the sensor registered dry. The placement of the sensors was such that the engine should shut down before they ran out of prop.
Normally the engines shut down on commands issued by guidance and the system had a small amount of prop remaining. (note: carrying extra prop to orbit wastes payload capacity, carrying too little means you don't go to space)
Here's some simple linear data for shutdowns from different power levels. This is for the (rather old) FPL version of the SSME (see the taxonomy of the SSME in my answer to Which STS mission raised the normal engine throttle above 100%, and what change to the SSME made that possible?) but should be somewhat representative. It's based on data supplied for use in simulator models at Johnson Space Center. This is chamber pressure data but thrust should be roughly proportionate. Y axis in psi, X axis in seconds.