The right-hander threw the first perfect game in the 128-year history of the franchise and the 22nd perfect game overall in major league history.
Cain credited catcher Buster Posey for calling the perfect game, saying, "I can't thank Buster enough. I didn't even question once what he was calling."
Cain also set a career high with 14 strikeouts -- matching Sandy Koufax for most ever in a perfect game.
"Incredible night," manager Bruce Bochy said.
The most incredible defensive work came from right fielder Gregor Blanco, who raced into the gap in right center chasing a drive by Jordan Schafer leading off the seventh. Blanco, back to the plate, arm full outstretched, made the grab on the warning track, left his feet and hit the ground, an astonishing play. Melky Cabrera also turned in two nice running catches in left field.
Blanco also provided a homer -- with Cain on base -- in the Giants' 10-0 win over the Astros. Cabrera and Brandon Belt also homered; Belt had hit his first homer of the season the previous night.
The final out Wednesday came when pinch-hitter Jason Castro hit a bouncer to third baseman Joaquin Arias, who backed up slightly and then made a strong throw to first baseman Belt as the Giants streamed out of the dugout to mob Cain.