You are quite lucky that you were not injured. Perhaps you should take a step back and plan it out a little better. Proper shop safety should always be followed, even on small jobs.
For starters, the piece of stock you were trying to machine is far too short to be cut with a router safely. The minimum length that can be cut with a router is around 12". For these cuts, you should also be using a fence with a featherboard attached to it to prevent kickback. A push stick should also always be used. A rule of thumb is to keep aboutat least a foot of distance between your hands and the bit at all times when the toolrouter is in operation.
Try starting with a longer piece, and then make all of the necessary cuts before trimming it down to length. You can keep the leftover piece, and use it on another project in the future.