The Giants initially seemed to be well on the way to a win with a two-run lead in the ninth and closer Santiago Casilla on the mound.
Houston then tied it on a bizarre play when Chris Snyder appeared to end the game on a strikeout, but the ball got away from the catcher, Sanchez. No one covered first base to receive the put-out, and Moore came around to score the tying run.
The victory, combined with the Los Angeles Dodgers' loss to San Diego, vaulted the Giants into first place in the National League West and allowed them to clinch their three-game set against the Astros.
Lytro unveils camera that can focus a photo after shooting it
'How to Train Your Dragon 2' releases 5-minute clip