Cain had four 3-2 counts and never gave in against an Astros team that had been swinging the bat well in June.
"He just didn't make many mistakes," Astros left fielder J.D. Martinez said. "It felt like everything was going his way. He was getting calls when he needed them, he was making great pitches when he needed to, and it just felt like he didn't make many mistakes."
Houston was also no-hit in 1963 by Juan Marichal of the Giants, in 1969 by Jim Maloney of the Reds, and in 1997 in a two-pitcher effort by Pirates Francisco Cordova and Ricardo Rincon, but none of them were this dominating.
The Astros thought Cain tired somewhat toward the end of the game, but they still weren't able to get a runner on base. Brian Bogusevic and Chris Snyder flied out to left field to start the ninth, sending a crowd that had been on its feet into a constant roar.
Jason Castro, whose only previous career at-bat against Cain resulted in a home run, pinch-hit and represented the Astros' final chance to avoid making dubious history. Castro hit a grounder to third baseman Joaquin Arias, who took an awkward step backward before throwing across the diamond to get Castro by two steps for the final out.
Cain's teammates mobbed him near the mound.
"Any pinch-hit at-bat is, for me, tougher than a normal at-bat, obviously, because you're coming off the bench, coming in cold," Castro said. "With a guy going like that, when he's got his A-game going, it's a tough at-bat. He made some good pitches, and that's what he was doing all night."
Cain (8-2) benefited from an offensive outburst in which the Giants scored in each of the first five innings, hitting three two-run homers, to take a 10-0 lead. The pitcher also had a pair of sterling defensive plays made behind him.
Left fielder Melky Cabrera hauled in a blast off the bat of Snyder in the sixth inning that died at wall, and in the seventh, right fielder Gregor Blanco made a spectacular diving catch on the warning track in the gap in right-center field to rob Jordan Schafer of what appeared to be a hit off the bat.
"For the most part, you need those plays to throw a perfect game," Schafer said. "Melky made a really good play on Snyder. I thought that ball was going to be definitely out when he hit it. [Cain] threw well and pounded the strike zone, and he even threw some pitches in the seventh and eighth when he had full counts and threw some changeups. That says a lot for the confidence he has in his other pitches."
Schafer nearly had a double in his at-bat in the fourth inning when he scorched a grounder over first base that was called foul by umpire Mike Muchlinksi. Schafer wound up striking out, but he and manager Brad Mills both thought the ball was fair.
"There's not really a good replay that shows anything, but I thought it was fair," Schafer said. "Just the way it works."
Astros starter J.A. Happ (4-7) suffered his worst outing of the season and lost his fourth consecutive start, allowing 11 hits and eight earned runs in 3 1/3 innings.
The Giants, who had hit only six homers at home entering the series, got a two-run shot from Cabrera in the first inning and a two-run homer to center by Brandon Belt in the second. Blanco hit a two-run homer off Rhiner Cruz in the fifth inning, giving San Francisco five homers in two games against Houston.
"It seemed like it was just hard for me to keep them from dropping the ball in or whatever," Happ said. "On a night like that, when it seemed like it was that hard for me, you have to give their guy credit for doing that and a lot more. He kind of set the tone, and you knew it was going to be a tough game. They jumped out to an early lead and stayed on it, and it's tough to stay in the game and come back from that."