PITTSBURGH (AP) -- Adam Frazier hit a two-run homer off Milwaukee closer Corey Knebel with two outs in the ninth inning to lift the Pittsburgh Pirates to a 6-4 victory on Wednesday night.
The Pirates tied it in the eighth on a throwing error by Knebel then ended a seven-game losing streak when Frazier homered into the first row of seats in the right-field stands.
Jesus Aguilar and Domingo Santana homered for the Brewers but Milwaukee missed a chance to pull into a tie with Colorado for the second wild-card spot in the National League.
Knebel (1-2) had converted 21 straight save opportunities. Milwaukee lost for just the third time in its last 12 games.
Felipe Rivero (5-2) earned the victory in relief. Frazier finished 2 for 5 with four RBIs. Starling Marte added two hits for the Pirates.
The Brewers are trying to lock up the franchise's third playoff berth since 1982. The bullpen has keyed Milwaukee's persistent chase of the first-place Cubs and manager Craig Counsell didn't hesitate when rookie starter Aaron Wilkerson ran into trouble in the third inning.
The Pirates ended a 21-inning scoreless drought when Frazier drilled a two-run triple and Marte followed with an RBI single to put them up 3-2, their first lead in nine days. It didn't last. Jacob Barnes came on for Wilkerson, a 28-year-old making his first major league start, and Pittsburgh's bats immediately went quiet.
The Brewers used eight pitchers in all and moved in front in the seventh thanks to another erratic performance by Tyler Glasnow.
Glasnow started the season in the rotation but was sent back to Triple-A Indianapolis due to control issues. Though he was dominant again at Triple-A, the command problems resurfaced again. He walked four of the six batters he faced, and Eric Thames' RBI double tied the game. The Brewers reclaimed the lead when Pittsburgh reliever A.J. Schugel walked in the go-ahead run.
Knebel came on for a four-out save with tying run at second in the bottom of the eighth. Knebel got David Freese to hit a grounder, but Knebel's throw to first sailed wide, allowing Andrew McCutchen to race home from second.
An inning later, Milwaukee's chance to pull even with Colorado was gone.
Brewers: RHP Jimmy Nelson is expected to miss a significant portion of the 2018 season while recovering from a partially torn labrum. Nelson suffered the injury after dislocating his shoulder while sliding back into first base against the Cubs earlier this month. "When you get something taken from you on something that's bad luck frankly, it's tough to swallow," Counsell said. Nelson went 12-6 with a 3.49 ERA this season.
Pirates: 2B Josh Harrison's surgically repaired left thumb will remain in a splint for the next 2-3 weeks but should be healed in time to go through his typical offseason workout program, trainer Todd Tomczyk said Wednesday. The same goes for C Francisco Cervelli, who is recovering from a sore left quadriceps.
Brewers: Begin a pivotal four-game series at home against the Chicago Cubs on Thursday. Zach Davies (17-9, 3.89 ERA) starts the opener for the Brewers, who are 8-7 this season against the World Series champions.
Pirates: Are off Thursday before welcoming St. Louis to PNC Park for a three-game set starting Friday. Ivan Nova (11-14, 4.20 ERA) faces Michael Wacha (12-8, 4.02).