Justin Maxwell's two-out double to right field scored Scott Moore, who had walked. Casilla then got Chris Snyder to strike out, but his curveball in the dirt got past Sanchez for a wild pitch, and Sanchez's rushed, off-balance throw to first pulled Brandon Belt off the bag and allowed Snyder to reach safely and Maxwell to score the game-tying run from second base.
Sanchez said afterward that he partially rushed the throw in his desire to get Lincecum the win after his first half of well-documented struggles.
"I tried to get the victory, and I tried to do too much," Sanchez said. "I tried to go too quick on that play, and I had a lot of time with the catcher running. That's what happens when you try to do too much."
But Sanchez would have his chance to come through. The bottom of the 12th inning started with Sandoval hustling down the line to beat out a slow chopper to Astros shortstop Brian Bixler for an infield single, and he then advanced to second on Angel Pagan's single to center to set up Sanchez's winning hit.
"You're going to make mistakes in the game, and he had to put it behind him," manager Bruce Bochy said. "That's a tough way to get a blown save, and Sanchy took it pretty tough. He was upset with himself."
Thanks to his first wild pitch of the season, Casilla has now blown four of his last six save opportunities.
Sanchez's game-winning single, though, came back to save Lincecum's gem after two forgettable road outings to conclude the first half.
Lincecum was pulled after 3 1/3 innings in both of his two previous starts before the All-Star break against the first-place Nationals and Pirates, giving up a combined 13 earned runs. But he bounced back by allowing only five hits, all singles, and one walk in his best statistical start of the season.
"The big thing for me was just being aggressive, trying to command the zone," Lincecum said. "I got out in front with my fastball, and I fed off of that as the game went on. That was the difference today, just being aggressive."
The start was reminiscent of Lincecum's last start at AT&T Park, when he struck out eight batters in seven shutout innings against the Dodgers on June 27. Now with a 15-inning scoreless streak at home, Lincecum has a 2-4 record and a 3.43 ERA at home compared to going 1-6 on the road with a 9.00 ERA.
"Outstanding," Bochy said of Lincecum's night. "He got better as he went, and he had a good tempo and rhythm out there. He had his command of all his pitches, and that was the Timmy we know."
Lincecum scored the game's first run in the fifth when he scored from third base on Melky Cabrera's single to right field. Back-to-back doubles from Pagan and Sanchez to open the sixth inning gave the Giants another run in support of Lincecum's fifth quality start of the season.
The Giants are now 5-1 in extra-inning games this season, while the Astros fell to 0-9.