The Cardinals moved two games in front of Pittsburgh for the lead in the National League Central.
Wainwright (17-9) worked 7 2/3 innings and gave up 10 hits while throwing 121 pitches. He escaped continuous trouble, however, by striking out eight and eventually left the game with two on and two out in the eighth.
Wainwright helped his own cause with a run-scoring double in the third and then scored on a single by Matt Carpenter to tie the game at 2-2.
St. Louis went in front for good in the fourth when Wainwright singled in Yadier Molina.
Tyler Chatwood (7-5) was charged with the loss after giving up four runs on six hits in eight innings.
Kate Middleton recycles dress at movie premiere
Jordana Brewster on Paul Walker: 'He was an enormous presence in my life'