SAN FRANCISCO -

Tim Lincecum didn't duplicate his no-hit effort Tuesday night.

But he came so close, he insisted he was just as happy afterward.

The National League's reigning Player of the Week followed up his no-hitter with eight innings of shutout ball, pitching the San Francisco Giants to a 5-0 victory over the St. Louis Cardinals in the opener of a three-game series.

The win got the month of July off to a winning start for the Giants, who struggled to a 10-16 record in June, the fourth-worst mark in the majors.

Winning for just the second time in a stretch of eight consecutive home games, the Giants were able to regain first place in the National League West by a half-game, leap-frogging the Los Angeles Dodgers, who were beaten by the Cleveland Indians.

Third baseman Pablo Sandoval belted his 100th career home run, a two-run shot in a three-run fourth inning, and right fielder Hunter Pence had two hits and scored twice, highlighting an eight-hit Giants attack on four Cardinals pitchers.

"Good win for us," assured Lincecum, who was more than willing to share the credit six days after commanding the spotlight with his no-hitter against the San Diego Padres. "We needed something positive to happen."

Attempting to ignite a spark under a team that had lost 12 of its previous 14 home games, Lincecum (7-5) allowed four hits in his 113-pitch effort. He walked two and struck out six.

"I tried to do everything the same (as in the no-hitter)," said Lincecum, who for the first time in his career has shut out consecutive opponents for at least eight innings apiece. "Last game I think I was 30-30-30 (fastballs, sliders and change-ups). I think I was something like that tonight, too."

It was a marked improvement over the follow-up to his previous no-hitter last season, when he got bombed by the Cincinnati Reds, allowing a career-worst eight earned runs in 3 2/3 innings.

Only three Cardinals baserunners advanced as far as second base, two of which came when St. Louis loaded the bases with no outs in the fourth inning of what then was a scoreless game.

Lincecum got out of the jam unscathed by striking out left fielder Allen Craig and center fielder Jon Jay before getting second baseman Daniel Descalso to ground out to second.

Cardinals manager Mike Matheny saw that as the turning point in the game.

"That does a lot for your confidence," the ex-catcher said of Lincecum's escape act. "I don't know if you believe in momentum, but it's not a coincidence that they came right back (offensively) with a big inning."

The Giants finally gave Lincecum some run support in the last of the fourth. Sandoval's homer to left field, his 10th of the season, came after Pence had opened the inning with a single and then scored on an RBI double by catcher Buster Posey.

Sandoval knew he was sitting on 99 homers, and admitted to celebrating a bit on his way around the bases. He had a bottle of champagne waiting for him at his locker after the game.

"It's hard to even get one," he said of hitting home runs at the major league level. "To get 100 means a lot to me. I was a little bit excited (rounding the bases)."

The Giants added to the lead in the fifth, making it 5-0, on an RBI double by Pence that scored center fielder Juan Perez, and catcher Hector Sanchez's infield out that scored Pence.

Left-handed starter Marco Gonzales (0-1) took the loss in his second major league start. The 2013 first-round draft pick gave up five runs on seven hits and four walks in 4 1/3 innings. He struck out two.

"He's been better than his numbers would indicate," Matheny said of Gonzales. "I saw some very good innings, some very good pitches. Then it kinda snowballed on him.

"Young pitchers are going to make some mistakes. We ran into a ballclub here, they weren't going to let him get away with any mistakes."

Shortstop Jhonny Peralta had the Cardinals' only extra-base hit, a double. Losing for the fifth time in its last seven games, St. Louis saw its record fall to 4-4 on a 10-game trip.

Lincecum's bid for consecutive no-hitters ended six batters into the game, when Craig lined a one-out single up the middle in the top of the second inning.

Right-hander Jean Machi relieved Lincecum to start the ninth and closed out the win. Machi allowed one hit.

The shutout was the seventh of the season for the Giants, three of which were started by Lincecum.

NOTES: The Giants won the first game of a series for the first time since beating the New York Mets on June 6. ... RHP Tim Lincecum extended his string of scoreless innings to 17, his longest stretch since a 21-inning run in May of 2011. ... 3B Pablo Sandoval became the 19th player in the San Francisco era of Giants history to record 100 home runs. ... For the third time in five games, the Cardinals faced a pitcher who threw a no-hitter this season. They opposed the Los Angeles Dodgers' Josh Beckett on Thursday and Clayton Kershaw on Sunday. The last team to face three no-hit pitchers over a five-game stretch was the Pittsburgh Pirates, who went up against Don Cardwell, Lew Burdette and Warren Spahn from Sept. 22-25, 1960. ... Perhaps not coincidentally, the Cardinals have been shut out in three of their last five games. ... The Cardinals promoted OF Oscar Tavares from Triple-A Memphis to fill a roster spot created when they demoted RHP Jorge Rondon on Sunday. Tavares started Tuesday in right field and went 0-for-3 with a walk. ... Giants CF Angel Pagan (neck inflammation) announced before the game he would fly to Los Angeles on Wednesday to see a back specialist. He was eligible to come off the 15-day disabled list Tuesday, but he felt pain in his back while running Monday, prompting a change in plans.