Veteran shortstop Orlando Arcia had two home runs, including a go-ahead two-run home run in the 13th inning, for the Brewers. The 24-year-old hit Alex McRae's 0-1 pitch for his sixth home run of the year.
Arcia, who entered play with a .262 average, also had a two-run home run off Nick Kingham in the second inning. Arcia finished Saturday with three hits in six at-bats.
The win, Milwaukee's 33rd of the year, gave the Brewers a share of first place in the NL Central Division with the Chicago Cubs.
Down 10-8 in the top of the ninth inning, Brewers rookie Keston Hiura tied the game with his fifth home run of the year. Hiura hit Felipe Vazquez's 1-0 pitch over the left field wall with one out.
Milwaukee had a 5-0 lead in the third inning after Moustakas' 16th home run of the year. Arcia's first home run of the game, a two-run shot that drove in Eric Thames, came in the second inning against Nick Kingham.
The Pirates (28-29) slowly clawed back before taking a 10-8 lead on Starling Marte's three-run home run in the eighth inning.
Christian Yelich hit his 22nd home run of the year for the Brewers. Jose Osuna had a pinch-hit, two-run home run for the Pirates.
The teams combined for seven home runs and 35 strikeouts.