The same thing happens to the air in the car. When the car stops the air keeps moving forward. This results in more air, or higher air pressure, in the front of the passenger compartment.
In most air bags, the sensor triggers chemical reactions that produce nitrogen gas from chemical tablets stored in the unit. The gas whooshes into the bag and inflates it in only a few milliseconds.