First, your leg muscle contract and squeeze the blood vessels near them to pump blood toward your heart. Then the increased amount of blood returning to your heart stretches the heart and cause it to beat faster and with more force. Then your leg muscles relax and the veins near them fill with blood to start the next cycle. When you run fast, your leg muscle do a considerable amount of the work pumping blood through your body. If you stop suddenly, the blood pools in your legs and your heart has to pick up the slack.
At the end of a long race, your heart may not be able to pump more blood, so not enough reaches your brain and you end up unconscious. Researchers at the University of Cape Town in South Africa analyzed data on runners who collapsed during an ultramarathon. Most cases occurred after the runner crossed the finish line. The few cases of collapse away from the finish line were caused by diseases such as asthma and heart damage.
When you slow down gradually, you allow time for your heart to pump harder to make up for the loss of pumping by your legs. However, cooling down will not prevent muscle soreness, which is caused by tearing your muscle fibers during exercise.