The Giants have allowed just four runs in their past five games but have won only three of those because of a pair of 1-0 losses. They also won a 1-0 game in that span.
Then they had this tight duel that featured strong outings from both starters.
"That's kind of our way," manager Bruce Bochy said. "The slogan: Giants baseball, torture. Or whatever it is. It's the way we do things. It's good for these guys because you can't lose your concentration or focus out there when you're in games like this."
The Giants won for the 10th time in 14 games to move within a half-game of first-place San Diego in the NL West. San Francisco is also a half-game behind Atlanta in the wild-card race.
The Giants blew plenty of scoring chances before finally breaking through against Billingsley (11-10) in the seventh to end a streak of 29 2/3 innings without an earned run against the right-hander.
Travis Ishikawa started it with a one-out double as a pinch hitter for Cain, who had thrown seven scoreless innings. The hit snapped a 13 at-bat hitless streak and was Ishikawa's first hit since Aug. 18.
Pinch runner Emmanuel Burriss moved to third on a wild pitch, but it looked as if the Giants might waste another scoring opportunity against Billingsley when Eugenio Velez hit a comebacker for the second out. That's when Fontenot delivered with his soft single to center field.
"That couldn't have played out any better than to have Ishi come in to get that double and for us to be able to get him in," Cain said. "He really did a great job."
Billingsley allowed six hits and walked two in seven innings, striking out seven. He lost to San Francisco for the first time in five starts this season but still has an 0.74 ERA against the Giants in 2010.
"Matt was throwing a good game also and I knew I had to match him," Billingsley said. "He just fought off the pitch and was able to get it over the infield. I executed my pitches, just the results weren't there."
The Dodgers have scored just 21 runs in their past 10 games, and the lack of offense is derailing their chance at a third straight division title.
"Leaving spring training I thought that was going to be our strong suit," manager Joe Torre said. "I really didn't know where the pitching was going to wind up ... but I thought if there was one thing we were able to take for granted it was that we were going to be productive. Actually the first half if you look at some numbers, we were third or fourth in runs scored. Then the second half has been a complete reversal of that."
Cain (12-10) gave up three hits, walked none and didn't allow a runner to get past first base. He beat the Dodgers for the second time in three starts after going winless in his first 14 games against Los Angeles.
The teams picked up where they left off from the opener of the series when Clayton Kershaw beat the Giants 1-0 on an unearned run that scored on an error by shortstop Juan Uribe. The Dodgers won despite getting only one hit against Barry Zito and the bullpen. The Giants became the first team in 39 years to lose two games in one season when allowing one or fewer hits, having lost the same way to San Diego on April 20.
The Giants threatened against Billingsley, but were unable to break through until the seventh. They loaded the bases in the first inning before Sandoval struck out to end it. Fontenot hit a drive to the warning track in left field with two on to end the fifth and Billingsley struck out Sandoval and got Cody Ross to fly out to center with two on in the sixth.
The Kansas City Royals lost twice in 1971 in games in which they allowed only one hit. ... San Francisco leads the majors with a 1.55 ERA this month. ... Giants RF Jose Guillen had an epidural for a bulging disk in his neck and could be available Thursday. ... Dodgers 2B Ryan Theriot is hitless in his past 25 at-bats, including a close play at first base on an attempt for a bunt single in the sixth.