What causes the engine to stall while driving?

There are several reasons an engine may stall while driving, here are three.

The fuel tank is empty and the engine is starved of fuel.

Not enough power to climb a hill causing a stall.

Faulty or damp electronics on a petrol engine can also cause a stall.