Hamels (14-6) won his third straight start, reaching a double-digit strikeout total for the 20th time in his career.
The left-hander limited the Brewers to three runs on eight hits while issuing a single walk as the Phillies notched their first win in a four-game series at Miller Park.
Jonathan Papelbon recorded the final four outs to collect his 27th save.
Milwaukee's Mike Fiers (6-6) gave up four runs on five hits over five full innings.
Beautician charged with giving client fatal silicone butt injection
Attkisson leaves CBS News, reportedly over network's 'liberal bias'