PITTSBURGH -- After nearly 4 1/2 months of inconsistency, the St. Louis Cardinals finally are starting to hit their stride.

Left fielder Matt Holliday's two-run single capped a seventh-inning rally, and right-hander John Lackey pitched one-run ball over seven innings to lift the Cardinals to a 3-2 victory over the Pittsburgh Pirates on Monday night.

It marked the Cardinals' ninth win in their past 12 games, the best stretch in the defense of their National League title. They drew within one game of the Milwaukee Brewers, who played later at San Diego, in the NL Central race.

"We're just playing good baseball in all phases on the game," Holliday said. "The pitching is giving a chance to win, we're scoring runs on a pretty consistent basis, and the defense has been good. It's really as simple as that. We're just going out and trying to win games."

Lackey (2-1) allowed seven hits while walking one and striking out three. He has given up two earned runs or fewer in four of his five starts since being acquired in a July 31 trade with the Boston Red Sox.

"I'm still trying to learn the lineups in the National League," Lackey said. "I'm going with my strengths first, and then we adjust from there. That's what we did tonight, and we turned (four) double plays, which always helps."

Cardinals closer Trevor Rosenthal gave up a leadoff home run to center fielder Andrew McCutchen in the ninth inning that cut the margin to 3-2. Rosenthal got left fielder Starling Marte to fly to center with a runner at second for the final out to seal his 39th save in 44 opportunities.

Holliday and second baseman Kolten Wong had two hits each for the Cardinals.

Reliever Jared Hughes (6-4) gave up all three Cardinals runs in two-thirds of an inning after starter Francisco Liriano pitched six scoreless innings. Liriano gave up four hits, walked three and struck out eight.

Pirates manager Clint Hurdle said he took Liriano out because the left-hander walked two batters in the sixth inning and was losing command of his pitches.

Hurdle said of Hughes, "It was just a night where he didn't get the ball to where he wanted to."

The Pirates' runs came on solo home runs by McCutchen and first baseman Pedro Alvarez, whose solo shot in the second inning opening the scoring. It was McCutchen's 20th homer of the season and third in past four games. Alvarez hit his 18th.

McCutchen had three hits and Alvarez two as the Pirates lost their second game in a row after a three-game winning streak. They fell two games behind the San Francisco Giants, who hosted the Colorado Rockies in a late game, in the race for the second NL wild card.

The Cardinals beat the Pirates for the fifth time in their past six meetings but failed to score at least four runs for the second straight game after doing so for 10 consecutive games.

"They're a good team," Liriano said. "We've just need to put this behind us and play the way we've been playing."

NOTES: The Pirates optioned rookie RF Gregory Polanco back to Triple-A Indianapolis after he had only one hit in his last 30 at-bats, and they purchased the contract of OF Jose Tabata from the same club. OF Travis Snider will get the bulk of the playing time in right field. ... Pittsburgh INF Clint Barmes was activated from the 15-day disabled list, and INF Jayson Nix was designated for assignment. ... Pirates RHP Charlie Morton (right hip inflammation/sports hernia) will make a rehab start Thursday night for Double-A Altoona. ... Cardinals C Yadier Molina (torn ligament in left thumb) will begin working out with Double-A Springfield on Tuesday, and RHP Michael Wacha (stress reaction in right scapula) will join him Wednesday. The plan is for Molina to play in a rehab game Wednesday after Wacha pitches live batting practice before the game. ... St. Louis recalled LHP Tyler Lyons from Triple-A Louisville and optioned INF Greg Garcia to Springfield, providing the Cardinals with an extra reliever after the bullpen pitched 11 innings in the previous two games. ... St. Louis RHP Lance Lynn (14-8, 2.78 ERA) is scheduled to face Pittsburgh RHP Gerrit Cole (7-4, 3.69 ERA) on Tuesday in the middle game of the three-game series.