Soreness in the muscle during and immediately following exercise manifests as mild pain and stiffness that makes it hard to continue exercising. Muscle soreness usually goes away relatively quickly.
Prolonged muscle soreness is called 'Delayed Onset Muscle Soreness', or DOMS for short. It is more delayed in its resolution and can sometimes last for days. This is the soreness that somebody would feel after a hard run or leg session and be unable to easily walk up stairs the next day.
There are various things that contribute towards DOMS.  Including:
Lactic Acid is commonly thought to induce muscle failure or soreness, but has not been shown to be the causative factor. It is highly correlated though  , as lactic acid is produced when the muscle is sore; however its more of a fuel source than a soreness causing agent.   
There are various mechanisms of reducing DOMS. 
Some light exercise, or moving the affected joints and muscles, can also alleviate DOMS.   This may be due to merely moving the affected muscles, as 'whole-body vibration therapy' has recently been suggested to do similar.  
Cryotherapy, or ice water submerging, has beneficial anecdotes by various athletes but has not been shown to be of much benefit in randomized controlled trials.   That being said, cryotherapy may hold some potential in cases of muscular trauma such as hamstring tears or intense muscular strains.    Cryotherapy's effectiveness may be closely tied in to the degree of muscular damage, and serve as a bridge between such anecdotes in high level athletes and a lack of results in novice trainees in intervention studies. 
Proper pre-workout nutrition can also play a role in preventing DOMS, as BCAA supplementation has been shown to be beneficial  (and can be consumed through whey protein or protein-containing foods)
Stretching (static) before or after exercise is not significantly effective in reducing DOMS from exercise. 
Related Nutrition Articles
- My muscles are not sore after a workout. Am I working out hard enough?
- What are the benefits of resistance training?
- I am a female. Will lifting heavy weights make me bulky?
- Will lifting weights convert my fat into muscle?
- Does resistance training work for the elderly?
- Why you shouldn't be always taking antioxidants, especially if you want to build muscle
- Does dark chocolate’s epicatechin content promote muscle growth?
- Does ashwagandha increase testosterone?
- Can arachidonic acid work as a bodybuilding supplement?
- How does protein affect weight loss?
- Does aspartame cause headaches?
- Supplementing for better joint health
- The effects of athletic massage on delayed onset muscle soreness, creatine kinase, and neutrophil count: a preliminary report . J Orthop Sports Phys Ther. (1994) Smith LL, et al.
- Biochemistry of muscle fatigue . Biomed Biochim Acta. (1986) Hultman E, Spriet LL, Söderlund K.
- Muscle fatigue: lactic acid or inorganic phosphate the major cause . News Physiol Sci. (2002) Westerblad H, Allen DG, Lännergren J.
- Lactic acid and exercise performance : culprit or friend . Sports Med. (2006) Cairns SP.
- Recent advances in the understanding of skeletal muscle fatigue . Curr Opin Rheumatol. (2002) Westerblad H, Allen DG.
- Delayed onset muscle soreness : treatment strategies and performance factors . Sports Med. (2003) Cheung K, Hume P, Maxwell L.
- The effects of ibuprofen on delayed muscle soreness and muscular performance after eccentric exercise . J Strength Cond Res. (2003) Tokmakidis SP, et al.
- The isolated and combined effects of selected physical activity and ibuprofen on delayed-onset muscle soreness . J Sports Sci. (2005) Rahnama N, Rahmani-Nia F, Ebrahim K.
- Light concentric exercise has a temporarily analgesic effect on delayed-onset muscle soreness, but no effect on recovery from eccentric exercise . Appl Physiol Nutr Metab. (2006) Zainuddin Z, et al.
- Whole-body vibration and the prevention and treatment of delayed-onset muscle soreness . J Athl Train. (2011) Aminian-Far A, et al.
- Influence of vibration on delayed onset of muscle soreness following eccentric exercise . Br J Sports Med. (2007) Bakhtiary AH, Safavi-Farokhi Z, Aminian-Far A.
- Ice-water immersion and delayed-onset muscle soreness: a randomised controlled trial . Br J Sports Med. (2007) Sellwood KL, et al.
- Effect of cryotherapy on muscle soreness and strength following eccentric exercise . Int J Sports Med. (1997) Paddon-Jones DJ, Quigley BM.
- A return-to-sport algorithm for acute hamstring injuries . Phys Ther Sport. (2011) Mendiguchia J, Brughelli M.
- Hamstring strain injuries: recommendations for diagnosis, rehabilitation, and injury prevention . J Orthop Sports Phys Ther. (2010) Heiderscheit BC, et al.
- Cryotherapy to treat persistent muscle weakness after joint injury . Phys Sportsmed. (2010) Kuenze C, Hart JM.
- Does Cryotherapy Improve Outcomes With Soft Tissue Injury . J Athl Train. (2004) Hubbard TJ, Denegar CR.
- Effects of massage on delayed-onset muscle soreness, swelling, and recovery of muscle function . J Athl Train. (2005) Zainuddin Z, et al.
- Branched-chain amino acid supplementation before squat exercise and delayed-onset muscle soreness . Int J Sport Nutr Exerc Metab. (2010) Shimomura Y, et al.
- Stretching to prevent or reduce muscle soreness after exercise . Cochrane Database Syst Rev. (2011) Herbert RD, de Noronha M, Kamper SJ.