Emmanuel Burriss singled with one out and stole second, going to third on an errant throw by San Diego catcher Kyle Phillips.
Then with Stewart at the plate, Burris broke for home and Stewart laid down a sacrifice bunt to the left of the mound, allowing the Giants' runner to score easily for a 4-3 lead.
The play made a winner of Javier Lopez (5-1), who tossed two scoreless innings. Brian Wilson made it interesting in the bottom of the 11th, allowing three walks before finally nailing down his 28th save.
Andres Torres and Nate Schierholtz each had two hits and an RBI for first-place San Francisco, which took three wins in a four-game series with the Padres.
Orlando Hudson hit a two-run single for San Diego.