Since a Diesel engine has not ignition coils or spark plugs to ignite the fuel the only way to shut the engine off in a diesel engine is to cut the fuel supply off to the engine.
In some diesel engines and vehicles the engines ignition switch is connected to a fuel solenoid vale that opens when you turn the key on which then allows diesel fuel to pass through to the engine.
Some vehicles and diesel engines may have the electronic fuel injectors that the voltage is supplied to through the ignition.
But when you turn the ignition off the fuel injectors are shut off which then shuts the engine off.
I've had an old tractor that was set up to where the fuel pump for the diesel engine would be shut off when you turned the key off.
A diesel engine shuts off when there is no fuel going to it.
This is one way to stop a run away diesel engine.
You shut off the fuel supply to the diesel engine and it shuts off.
With a gasoline engine shutting the fuel supply off would also work to shut a gasoline engine off but when you turn the key off to the gasoline engine you shut off the electrical supply to the ignition coil or ignition coils which shuts the engine off.