ST. LOUIS -- Jake Westbrook received an early wake-up call Monday night.
"I made a mistake to the first hitter and then after that I settled in," Westbrook said. "I threw the game I think I'm capable of throwing."
Carlos Beltran hit his 26th homer for the Cardinals, who have won four in a row overall and seven straight at home. San Francisco had a three-game winning streak stopped.
Buster Posey also connected for the Giants.
Westbrook (11-8) won his fourth decision in a row, giving up seven hits and two runs. He struck out four and did not walk a batter. Westbrook has gone at least six innings in his last 11 starts.
But the night started off on the wrong foot for Westbrook, who quickly shook off the early blow to post four successive scoreless innings.
Westbrook began the four-game run with a three-hit, seven-inning shutout performance in a 12-0 win over the Chicago Cubs on July 21.
He continued to roll on Monday giving up one run on five hits over his final five innings.
St. Louis manager Mike Matheny was particularly impressed with Westbrook's ability to bounce back from the early home run.
"You never know when you start the game with a leadoff (homer) like that," Matheny said. "He was able to stay in there and find that sinker. He did a great job."
Cain (10-5) tied a season high by giving up five earned runs in 5 2/3 innings. The three-time All-Star absorbed back-to-back losses for the second time this season. Cain has allowed nine home runs in his last seven starts.
Cain, who has allowed 28 earned runs in 57 1/3 innings for a 4.40 ERA since throwing a perfect game on June 13, said he felt fine.
"I just need to make better pitches and get quicker outs," he said. "I've got to put away guys better."
San Francisco manager Bruce Bochy felt Cain threw better than his numbers showed.
"He was OK, they just did a great job of hitting him," Bochy said. "I thought he had good stuff. That's a good hitting ballclub. They're not at the top offensively for no reason."
Cain's ERA moved to 3.01, the highest total since it sat at 7.50 after a 7-6 loss at Arizona on April 8 -- his first outing of the season.
Jay paced a 12-hit attack with his second four-hit performance of the season. He also went 4 for 4 in a 7-0 win over the Chicago Cubs on July 22.
"Today I was able to get some hits and we got a big win," Jay said. "We've got to keep it going. We've got a short amount of games left and some ground to make to up. If we keep doing what we're doing, we're going to be all right."
With the win, St. Louis moved within six games of Cincinnati in the NL Central.
The Cardinals scored three times in the sixth to break a 2-all tie.
Matt Holliday doubled and came around to score on a sacrifice fly by David Freese. Yadier Molina and Jay followed with singles and Cain walked Rafael Furcal to load the bases for Carpenter, who drove a two-strike pitch to left field.
The Cardinals added three runs in the seventh to go up 8-2. Jay's two-run single was the key hit.
Beltran, who leads the NL with 78 RBIs, hit the first pitch of the second inning 418 feet to tie it at 1. Four batters later, Furcal broke out of an 0-for-14 slump with an RBI single the 10th pitch from Cain.
Pagan's first-inning homer was his seventh of the season. Posey tied it at 2 with his 17th homer in the sixth.
Molina extended his hitting streak to a season-long 10 games as did Posey. ... St. Louis INF Daniel Descalso hit in the leadoff spot for just the sixth time this season. ... Holliday has seven homers and 21 RBIs in his last 23 home games. ... Lance Lynn (13-4, 3.40) faces Giants LHP Barry Zito (8-8, 4.27) in the second game of the four-game series Tuesday. ... The Giants have picked up LHP Jose Mijares from Kansas City on waivers. They will announce a roster move in the next two days.