The Giants had a tough time getting the ball out of the infield against Phillies left-hander Cliff Lee.

Staying on top of the NL West is getting to be just as tricky for the defending World Series champs.

Lee threw a seven-hitter, allowing only two outs to be recorded beyond the infield, and San Francisco kept stumbling with its sixth defeat in seven games, a 2-0 loss to Philadelphia on Thursday night.

"He's got great stuff and had all his pitches going," Giants manager Bruce Bochy said. "When he's on he's as good as anybody and he showed it tonight. We battled well and got some guys on base. We just couldn't get a hit to drive in somebody."

That's been an ongoing problem for San Francisco, which is batting just .176 (18 for 91) with runners in scoring position over the past 14 games.

Though he got only two runs of support himself, Lee made it all academic. The lefty earned his 10th career shutout, needing just 74 pitches to get through the first seven innings and 106 overall.

That sliced San Francisco's lead in the NL West to one-half game over the Arizona Diamondbacks, who open a three-game series against the Los Angeles Dodgers on Friday.

"Obviously (Lee) doesn't need many runs as good as he is," said losing pitcher Madison Bumgarner. "The way he was throwing he looked like he could throw about 14 innings out there."

Bumgarner pitched well himself but took the defeat despite one of his best outings to date. The only two mistakes the young left-hander made came in the second inning when Hunter Pence and John Mayberry hit back-to-back home runs.

A postseason hero for the Giants last year, Bumgarner recovered after allowing two long balls in a game for just the second time this year and the first since June 15.

"He shows a lot of poise," Phillies first baseman Ryan Howard said of Bumgarner. "He gets himself into some tough situations but he finds his way out of them, too."

Bumgarner (6-11) retired 13 of 14 following Mayberry's blast. He went eight innings, allowing six hits, walking two and striking out nine.

"I was leaving them up for the first couple (innings) and obviously they made me pay for it," Bumgarner said. "That second inning cost me."

Lee (11-7) was commanding in his first regular season start against the Giants in two years, striking out eight, including Cody Ross four times, and not walking a hitter. He set down 10 in a row at one point in his major league-leading fifth shutout this season.

It was also some revenge for Lee, who lost twice to the Giants in last year's World Series pitching for the Texas Rangers.

Pence had three hits and drove in two runs and is hitting .360 (9 for 25) since joining the Phillies.

The Phillies, who have won seven straight since losing two in a row to the Giants in Philadelphia, remain undefeated since acquiring Pence, who homered in a Phillies uniform for the first time. Pence ended a 19-game, 67-at bat homerless drought when he connected on Bumgarner's first pitch in the second inning.

Bumgarner allowed the first three Phillies to reach in the first, but Jimmy Rollins was thrown out trying to steal third by Chris Stewart and Ryan Howard lined into a 5-6 double play.

The Phillies never had more than one runner on in an inning the rest of the way.

Pence added an RBI single in the ninth against Santiago Casilla.

NOTES: Giants IF Mark DeRosa was activated from the 60-day DL. IF Brandon Belt was optioned to Triple-A Fresno and LHP Alex Hinshaw was designated for assignment. ... LHP Jonathan Sanchez gets his first start since coming off the disabled list. He last pitched June 24. Sanchez is 3-1 with a 2.86 ERA in five starts against the Phillies. ... Giants OF Carlos Beltran is 1 for 6 lifetime against Phillies RHP Vance Worley, who pitches Friday.