Hamels (8-8) gave up just two hits and struck out nine in his career-best for a nine-inning game. The left-hander picked the potential tying run off first in the ninth and also stole a base, the first time for a Phillies pitcher since Curt Schilling in 1997.
Hamels has pitched 19 straight scoreless innings. Ryan Howard had the game's only RBI.
Jonathan Sanchez (6-11) was charged with the loss after giving up the lone run on three hits with three walks and eight strikeouts over six innings.