It's essentially a small, spring-loaded switch that's mounted somewhere in the vehicle, often under the dashboard or in the engine compartment (location varies by model year and vehicle). A strong enough jolt will trigger the switch, breaking the electrical circuit that supplies power to the fuel pump. This stops the flow of fuel.
To reset the switch after an accident (or if it's tripped inadvertently), you usually just need to push the switch back in. You'll then need to check for any damage to the fuel system before attempting to start the vehicle.