A car’s fuel system typically comprises a fuel pump, fuel tank, fuel lines, fuel filters, and fuel injectors. If any of these are compromised, there’s a good chance your car’s engine will stall.
The fuel pump pulls gasoline or diesel from inside the tank, into the lines, through the filters, and then to the injectors serving the engine’s combustion chamber. If the fuel pump is bad, it cannot draw enough fuel or muster enough pressure to get the fuel to the engine. Without fuel, the engine will stop — even while driving.
If the fuel pump is fine, the next culprits may be the fuel lines and filters. Debris or damage in the lines could clog and stop fuel from reaching the injectors. If the lines are fine, it might be time to service or substitute the filters (depending on your car).
Lastly, you might need to clean the fuel injectors in your car. Fuel injectors can also get clogged and stall your engine, but you will probably first notice symptoms appreciate rough idling, poor acceleration, hesitation while speeding, misfiring, etc. These signs are also similar to bad spark plugs since combustion is a core part of their function in the engine. You should also substitute your spark plugs while servicing your fuel system.