Milwaukee entered the bottom of the ninth facing a five-run deficit, but Jesus Aguilar led off with a solo home run off Phillies reliever Hector Neris, and Thames hit his three-run homer later in the inning with two outs. That prompted the Phillies to turn to Jake Thompson, who ended the game by retiring Christian Yelich on a flyout to deep center field.
The Brewers also had the tying run at the plate with the bases loaded in the eighth inning, but Phillies reliever Victor Arano struck out Travis Shaw.
The defeat denied the Brewers a third straight series victory, but they remained a half-game up on the second-place Cubs in the National League Central.
"We did a nice job offensively," Brewers manager Craig Counsell said. "We put the tying run up there in the eighth and put together a great inning in the ninth. We made them work hard for it."
Brewers starter Chase Anderson surrendered a season-high six runs and struck out five over 5 1/3 innings. Milwaukee's offense tried to help him out, coming back from a pair of two-run deficits in the first five innings.
In the ninth inning, Brewers closer Corey Knebel allowed his fourth home run of the season -- which turned out to be the game-winning run -- through 14 2/3 innings. Knebel allowed six homers in 76 innings during his All-Star season in 2017.
Three days into a stretch of 30 games in 31 days heading into the All-Star Break -- and with fellow starting pitchers Zach Davies, Jimmy Nelson and Wade Miley sidelined -- the Brewers were looking to get more outings like Anderson's seven-inning gem last Tuesday against the Cubs.
"We've got a game tomorrow," Counsell said. "We've got games moving ahead. We put a bunch of good arms out there today. That's who we've got."
MOMENTS THAT MATTERED Fear the Chin: Thames' tagline with the Brewers had been "Fear the Beard," but now it should be "Fear the Chin," after he hit two home runs on Sunday, including one to lead off the bottom of the first inning off Aaron Nola. Thames came off the disabled list last Monday after experimenting with his beard, citing too much free time while recovering from left thumb surgery. On Friday, he went with a more clean-shaven look, and his first-inning clout was his first homer since April 18.
"I'm just trying to take it one pitch at a time," Thames said. "It feels like Spring Training for me. It's a matter of getting my timing back and getting that process back in my mind, laying off stuff in the dirt."
The Brewers chased Nola from the game after 4 1/3 innings, ending his streak of 35 starts since May 31, 2017, of pitching at least five frames. Still, the Brewers had two runners on with no outs in the first and fourth innings but couldn't score.
"We scored a lot," Thames said. "It's one of those things where if you score under three runs but you leave 10, 15 guys on base, that's when you kind of get upset about yourself."
Yelich flies out: After Thames' second home run of the game in the ninth, Yelich hit a loud fly to deep center, but Odubel Herrera robbed him of extra bases and ended the game. To those in the dugout and in the stands, it seemed like the liner -- which had an exit velocity of 102.5 mph -- would have a chance to get to the wall.
"For real, we thought he went deep with just the way it looked off the bat," Thames said. "[Herrera] made a great catch. We were close to tying that game. It's a game of inches."
Phillies tee off: It took Anderson one pitch to allow as many hits as he did against the Cubs on Tuesday. Two pitches later, the Brewers were down two runs on Rhys Hoskins' second homer in two days. Anderson settled in after that and retired the next nine he faced, but another two-run homer in the fourth and two more runs in the sixth helped the Phillies pull away.
"Reminded me of growing me up in Texas a little bit, that weather out there today," Anderson said. "I wanted to hold their offense down but really wasn't able to do that."
Anderson, the Brewers' Opening Day starter, has now allowed more homers this season (15) than all of last season (14) in 64 fewer innings.
"Physically, I feel fine. Mentally, I feel good," Anderson said. "I guess it's just one of those things where you're trying to attack from Pitch 1 to Pitch 115, 120. That's the goal -- kind of like I did in the Cubs outing."
YOU GOTTA SEE THIS Aguilar can do the splits. At least, mostly.
The Brewers' 250-pound first baseman was forced to nearly do the splits when completing an inning-ending double play in the fourth. Anderson hit Nick Williams with one out, and Jorge Alfaro recorded a routine flyout to Thames in left field, but Williams ran on contact from first and was doubled up. A wide throw from shortstop Hernan Perez led to Aguilar reaching all the way to his left, ending with his legs fully spread.
MITEL REPLAY OF THE DAY The Brewers' two-run fifth that tied the game could have given them the lead, but Phillies manager Gabe Kapler won a challenge for the second straight day.
Yelich grounded to Franco at third base to open the fifth inning, but he was called safe after the throw pulled Carlos Santana off the first-base bag. Kapler challenged the call, which was overturned for the first out of the inning after it was ruled Santana did tag Yelich. Milwaukee's next three batters (Cain, Shaw and Aguilar) all reached base, and Cain and Shaw scored.
UP NEXT The Brewers hit the road for a quick three-game trip Pittsburgh beginning at 6:05 p.m. CT on Monday. Jhoulys Chacin (6-1, 3.32 ERA) will start for the Brewers, who are 12-3 when the right-hander starts this season. Chacin pitched six shutout innings in a 1-0 win over the Cubs last Wednesday, and he also tossed six innings of one-run ball against Pittsburgh in May. Trevor Williams (5-4, 4.38) starts for the Pirates.
Stephen Cohn is a reporter for MLB.com based in Milwaukee.