If you have an automatic transmission, put the gear in neutral.
If you have a manual transmission, push in the clutch and control your speed, if necessary, by balancing the use of the clutch and brake.
Put on your hazard lights.
If the pedal itself is stuck, while keeping aware of your surroundings, try and unhook the pedal with the top of your toes.
If you have power steering, do not switch off the engine otherwise steering will be a lot more difficult, which may prove to be more dangerous.
If the engine revs to a dangerous level, as a last resort, ensure the vehicle is in 'neutral,' switch the ignition off, making sure you do not lock the steering wheel and bearing in mind you will lose power to the brakes and steering. Note that you can also use the handbrake to slow down.
Try to coast to the side of the road, well away from moving traffic.
Only after stopping should you switch the engine off.