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.
N.J. man wakes up from 10-hour sleep with knife in back
Puzzle-maker slips 'Murdoch Is Evil' into Rupert Murdoch's Sunday Telegraph