It's certainly not unusual for a rug or carpet to suffer some kind of accidental saturation -- from a leaky roof, an overfilled bathtub, an actual flood, or perhaps simply a spilled glass of juice. Whatever the liquid, your only defense is to get it dried out as quickly as possible. Still, it's probably safe to assume you're going to have a mildew problem anyway; after all, mildew loves the damp, and rugs love to retain dampness.
You can kill any mildew hiding in your rug fibers by sponging in a mixture of half vinegar and half water. But you must take measures to ensure the rug dries thoroughly. If you can't set the rug or carpet out in the sun for a long time, you may want to use a hair dryer, set at a very low setting, and/or aim some electric fans at it. The goal, after all, is to defeat dampness!