At every marathon I've either run in or watched, I've always seen at least a few people walking during the last few miles, complaining that their legs are cramping. Some runners also experience muscle cramps towards the end of their long training runs. The culprit is often dehydration, so it's important that you hydrate properly before, during, and after your long runs and races. To prevent those painful muscle cramps, you need to replace sodium and other electrolytes lost through sweat, so it's especially critical that you make sure you consume sports drinks if you're running longer than 90 minutes.
Get more information on prevention and treatment of muscle cramps.