The Phils have won nine of ten and trail the N-L East-leading New York Mets by three games after trailing by eight and a-half on the second of June.
Newly acquired Tadahito Iguchi hit his first homer with Philadelphia. Aaron Rowand added a three-run drive for the Phillies.
Hamels is 12-and-5 with the win. He allowed one run on three hits in eight frames. Lilly, who had won his last six games, fell to 11-and-5.