Jeff Samardzija pitched into the ninth inning to help the Chicago Cubs take a 4-2 win over the St. Louis Cardinals in the second of a four-game set.

Samardzija (4-7) scattered seven hits and a walk and gave up two runs while striking out six over 8 1/3 innings for the Cubs, who have won four of six.

"It's a rivalry game, and with that aside, you have a respect for [the Cardinals] and how they play the game and how they set their lineup up, one through nine," Samardzija said.

"You know you've got to come at it," he said. "I'm watching film five days before, and trying to find some weaknesses, and you can look as hard as you want and you're not going to find it. You just know your margin of error against this team is real small and you've just got to deal with it."

Ryan Sweeney hit a two-run homer, Cody Ransom added a solo shot and Alfonso Soriano hit an RBI double in the win.

Carlos Beltran hit a solo home run and Yadier Molina added an RBI single for the Cardinals, who came into the game having won nine of 13 against the Cubs.

Adam Wainwright (10-4) failed to become the first 11-game winner in the majors and had a five-start winning streak snapped, giving up all four runs on seven hits over seven innings of work.

Samardzija tired to complete the game and got the first out of the ninth, but then gave up singles to Matt Holliday and Allen Craig, prompting Kevin Gregg to come out of the bullpen. Molina punched a single to right to score Holliday and make it a 4-2 game.

David Freese then hit a grounder to second and Darwin Barney made the toss to Starlin Castro, who tagged the bag but was unable to get the ball over to first. However, it was ruled that Shane Robinson, pinch-running for Molina, came out of the basepath and was called for interference, ending the game and giving Gregg his 10th save of the year.

The Cubs got all their runs in the game in the first inning, and they did it all with two outs.

Nate Schierholtz hit a double to keep the inning alive and Soriano followed with a two-bagger for the first run. Sweeney then hit his second homer of the year, a shot to right, and Ransom followed with his eighth of the season for a 4-0 lead.

"Four batters in a row -- if they had a happy zone, I found it," Wainwright said. "I threw it in the worst spot possible every time. I knew where I had to throw the ball. I have a scouting report. I have a game plan. And four hitters in a row I completely didn't execute a pitch and after that I settled down."

St. Louis got a man on base in four of the first five innings, but hit into three double plays to kill any scoring chances.

Beltran belted a two-out homer to right, his 17th of the season, in the sixth to make it a 4-1 game.

The Cardinals stranded another runner on base in the seventh inning, however, and Samardzija pitched a 1-2-3 eighth.

Game Notes

Wainwright fell to 6-6 in 28 games (19 starts) against the Cubs ... Samardzija moved to 4-2 in 17 games (6 starts) against the Cardinals ... Edwin Jackson takes the mound for Chicago in Wednesday's matchup, while Jake Westbrook is scheduled to start for St. Louis.