well that typically happens from acidosis. It is common in the 800 but not really in the 400 if you are fast and run correctly. In the 400 if you pace it correctly and are fast, the acid buildup in your muscles willl not get into the blood (and thus to the brain, which responds by shutting you down) until after the race is over. Watch video of olympic 400 and you will see that they cross the line looking ok then 15-20 secs later they are lying down, breathing like crazy as the acidosis hits. In the 800 you are still racing when the acidosis hits, which is why you see people locking up and slowing down in the last 60 meters.
As for what to do about it there are a few options.
1) Pace better. If you are going out too fast you could be costing yourself overall time by locking up in the end.
2) Run slower. Not a good solution but will solve the problem.
3) Train to enhance acid buffering. That would be very high speed intervals with moderate recovery and lots of reps. Something like 15 x 300 m at 800 m pace with 2 min slow jog rest.