Matt Cain took a three-hitter into the ninth in the opener of the four-game showdown between the rivals, who also will meet in a season-ending, three-game series at San Francisco from Oct. 1-3. San Francisco is one behind Atlanta in the wild-card race.

Cain (11-10) allowed David Eckstein’s leadoff single in the ninth followed by Ryan Ludwick’s homer to straightaway center, leading manager Bruce Bochy to turn to Javier Lopez and Ramon Ramirez to finish. Cain struck out eight and walked one.

It was the Giants’ third win in 12 games against San Diego this season. The Giants have two more losses than the Padres, who have played two fewer games than San Francisco.

San Francisco has won eight of 11 while the Padres have lost 11 of 14.

Jon Garland (13-11) allowed six runs and eight hits in five innings for San Diego.

Cardinals 11 Braves 4: In Atlanta, Colby Rasmus hit a pair of homers, Albert Pujols and Skip Schumaker also connected, and Adam Wainwright bounced back from a shaky first inning to lead the Cardinals to the win.

The Braves, looking to turn things around after a poor road trip knocked them out of first place in the NL East, jumped ahead 3-0 in the first inning. But the Cardinals rocked Jair Jurrjens (7-5) for five runs in the second — capped by Schumaker’s two-out, two-run drive — and Atlanta took its sixth loss in eight games.

Rasmus went 4 for 4 and drove in four runs, matching his career high in both categories.

Atlanta dropped a full game behind idle Philadelphia in the NL East.

Rockies 6 Reds 5: In Denver, Chris Nelson stole home in the eighth inning to send the Rockies to the four-game series sweep and their season-best seventh consecutive victory.

With one out and runners on the corners, Nelson broke for home before Nick Masset (3-4) threw his first pitch to Miguel Olivo . Inexplicably, Masset stepped off the mound, whirled to his left and toward second base.

Nelson scored easily to give the Rockies a 6-5 lead. He became the first player to take home for his first career steal since Dan Uggla of the Florida Marlins accomplished the feat on April 21, 2006, against the Philadelphia Phillies, according to STATS LLC.

Masset said he came set, stepped off the mound and initially thought Melvin Mora was going to second. He called it “a complete mistake” on his part.

Jason Giambi and Troy Tulowitzki homered for Colorado, which trailed 5-0 after two innings. Tulowitzki’s tying leadoff drive in the eighth was his 18th homer and sixth in seven games.

Astros 3  Dodgers 2: In Houston, rookie Chris Johnson hit a three-run homer in the sixth inning and the Astros rallied to get the victory.

Johnson, who struck out in his first two at-bats, drove a full-count pitch from Ted Lilly (8-10) to the train tracks in left field for his eight homer, erasing a two-run deficit. Hunter Pence singled to extend his hitting streak to 10 games and Carlos Lee walked to set up Johnson’s one-out drive.

Bud Norris (7-8) struck out seven in six innings for Houston, which has won three straight.

Andre Ethier hit a two-run homer in the first inning for the Dodgers, who have dropped six straight and eight of nine.