Cardinals starting pitcher Adam Wainwright was a few outs from suffering his third loss in four starts Tuesday against the Pirates, but a late rally got him off the hook.

Wainwright did not pitch poorly in the outing, allowing three runs in seven innings, and he was fine after a rocky start to the game. Wainwright allowed three runs in the first two innings on a pair of home runs, but closed his outing with five scoreless innings.

Wainwright struck out six and walked three, while throwing 71 of 122 pitches for strikes. He was in line for the loss, before the Cardinals rallied in the ninth to tie the game, 3-3. He remains 13-7, with a 2.71 ERA on the season.

Wainwright is set to make his next start Sunday against the Cubs in Chicago.