PITTSBURGH — The St. Louis Cardinals scored four runs in the ninth inning to defeat the Pittsburgh Pirates 4-2, erasing a two-run deficit with back-to-back home runs and a clutch double.

Pedro Pages and JJ Wetherholt hit consecutive home runs to open the ninth, and José Fermin followed with a two-run double that provided the winning margin.

Pittsburgh had controlled the game for most of the night. The Pirates carried a perfect game bid into the seventh inning before it was broken, and they held the Cardinals scoreless until the final frame.

The win carries extra weight given what St. Louis just endured. Days earlier, the Arizona Diamondbacks beat the Cardinals 4-3 by scoring four runs in their own ninth inning. Arizona's winning run came on a passed ball, with Nolan Arenado and Lourdes Gurriel Jr. contributing run-scoring hits during the rally.

Having been on the wrong end of that kind of comeback, the Cardinals answered with one of their own. That cuts both ways in a long season, but it is the kind of win that matters.