Nelson struck out six of his first eight batters he faced but gave up a single, a walk and a wild pitch in the fifth before Philadelphia took a 1-0 lead on Ty Kelly's sacrifice fly to right.
Nola put up zeroes through his first four frames as well, but Milwaukee answered in the fifth as Jonathan Villar reached on a two-out single, stole second and scored when Eric Thames doubled off the wall in center.
Ryan Braun drew a walk to keep the inning going but the Brewers couldn't cash in as Shaw flew out to right.
Hernan Perez put Milwaukee ahead with a leadoff homer in the sixth and Stephen Vogt followed with a walk but Nola retired the next three batters, including two strikeouts.
Herrera tied it up with a one-out, solo home run in the seventh inning.
Pat Neshek struck out the top of Milwaukee's lineup in order in the seventh to preserve the tie, but Shaw connected a 1-1 fastball from Joaquin Benoit (1-4) to open the eighth for his 20th home run of the season, giving the Brewers the lead.
Jacob Barnes (2-1) walked two in a scoreless eighth inning and Corey Knebel kept Philadelphia off the board in the ninth to lock down his 16th save of the season.
NOTES: LF Ryan Braun was in the lineup again Saturday but manager Craig Counsell said the veteran is day-to-day for the remainder of the season thanks to a nagging injury to his left calf that left him on the disabled list for nearly a month. "He's fine, but it's come back before," Counsell said. "I'm never going to say we are in the clear with that one. It's just one of those things we are going to have to deal with and he's going to have to be careful with it, and we are too. We are going to have to give him some breaks and get him out of some games." ... Phillies OF Aaron Altherr was unavailable Saturday after suffering a mild strain of his right ankle a day earlier. Manager Pete Mackanin was optimistic that Altherr, batting .288 this season, would only need a couple days to recover. ... The Phillies expect to get INF Cesar Hernandez back from a minor league rehab assignment next week when they travel to Miami. RHP Vince Velasquez, out since May 31 with a strained flexor in his right elbow, will likely be activated from the disabled list and start the series opener Monday.