The Brewers led 5-0 in the fifth inning, only to see the Pirates score the next five runs to forge a tie.
They grabbed a 6-5 lead in the seventh, but the Bucs once again knotted in score on the National League-leading 32nd homer of the year from Pedro Alvarez (4-for-4) in the bottom of the inning.
Then in the eighth, Betancourt doubled with one out against Bryan Morris (5-7), went to third on Scooter Gennett's bunt single and scored the decisive run on pinch-hitter Gindl's sac fly to right.
Ramirez went 4-for-5 with a solo homer and Jonathan Lucroy provided three hits, including a run-scoring single, as the Brewers claimed the first of a three-game set.
Rob Wooten (3-0) got credit for the decision and Jim Henderson secured the win with his 22nd save.
Neil Walker bashed a three-run homer for the second-place Bucs, who fell 1 1/2 games behind National League Central-leading St. Louis but remained 5 1/2 games ahead in the NL wild card standings.