The Astros lost their 13th consecutive road game, their longest such streak within one season since June 1990. (They lost their final 12 road games of 1996 and the first two of 1997.)
The Astros now travel to San Diego for a four-game series, followed by three in Arizona, before they return to Houston.
"I don't know why," Johnson said. "If we knew, we'd fix it. It's something we talked about over the break and during the workout [on Thursday]. We want to fix this road thing we have going on. It's definitely tough coming in here and facing these guys. They have a good ballclub, a good pitching staff. There is still time for us to turn it around. We have to start playing better baseball on the road and figure out how to win these close games."
The Astros had a chance to win this one. Their best opportunity came in the seventh inning, when they knocked out Cain. Brian Bogusevic had walked and, one out later, went to third on a hit-and-run single by Marwin Gonzalez. They had the tying run 90 feet away.
Pinch-hitter Brian Bixler fouled out against reliever Jeremy Affeldt, with catcher Buster Posey making the catch just inside the railing. Pinch-hitter Justin Maxwell then hit a flyout to deep right.
Over the final two innings, the Astros managed only one baserunner, when Scott Moore was hit by a pitch with two outs in the eighth.
Astros starter Bud Norris, a Bay Area native, took the loss on an afternoon that he struggled with his control but managed to keep his team in the game. He walked a season-high six batters in six innings, but only three runs scored.
The winning run, as it turned out, came home on Buster Posey's RBI single in the fifth.
"I thought Bud did a good job of working around his six walks," Astros manager Brad Mills said. "When a guy gives up six walks in six innings, you are glad to get out of there like we did. He gave us a quality start and a chance to win the ballgame."
Norris could have taken his team out of the game in the first inning. He gave up singles to three of the first four batters, producing one run, and then he walked a batter to load the bases. An out later, he walked a run in. Norris struck out Brandon Crawford to leave the bases loaded.
"I wasn't very sharp," said Norris, winless since May. "I struggled a lot early to find my consistency. I wanted to throw a lot more strikes, but I didn't. I thought I was close on a bunch. It's frustrating."
The Astros came back to tie the game. After Cain retired the first six batters, the Astros finally got to him. Gonzalez, who will be the shortstop while Jed Lowrie is on the disabled list, doubled in his first at-bat since coming off the disabled list. He scored two outs later when Cain made a bad throw to first on Jordan Schafer's bunt for an error.
In the fourth, Johnson doubled into left-center, driving in Bogusevic with the tying run. Johnson followed that with a baserunning mistake, though. He was thrown out trying to go to third on a ground ball to the shortstop.
"That's a situation we addressed," Mills said.
The Giants snapped the tie in the fifth. Pablo Sandoval led off with a double and he scored on Posey's single. The Giants held that one-run lead the rest of the way, as the Astros lost their second consecutive one-run game.
"To get a sweep is hard to do, I don't care who you are playing," Giants manager Bruce Bochy said. "These games were hard-fought games. They played well, and they have a lot of good young players, and we didn't do a lot with their pitching. They really fought us hard these last couple games, and they really could have gone either way."