The Milwaukee Brewers took advantage of mishaps by the Pittsburgh Pirates to take a three-run lead, then nearly let it slip away in similar fashion in the final inning.

The Brewers scored three runs in the third inning after reaching base on an error, one hit, two walks and two hit batsmen, only to commit two errors in the bottom of the ninth.

But with runners on first and third, Brewers reliever Joel Payamps struck out pinch hitter Andrew McCutchen to clinch a 3-2 win Wednesday night before 10,370 at PNC Park. The loss snapped a two-game winning streak for the Pirates, who can clinch a series win against the NL Central leaders Thursday afternoon.

In the ninth, Edward Olivares hit a chopper back to the mound that Payamps knocked down but Olivares beat the throw to first base, and the call stood upon review. Then Joey Wiemer dropped an Oneil Cruz fly ball in left field, putting the go-ahead run on base.

With two outs and runners on the corners, the Pirates sent McCutchen to pinch hit for Henry Davis. McCutchen hit leadoff home runs in each of the previous two games against the Brewers but went down swinging at a fastball at the top of the strike zone.

“We had a couple opportunities. We just didn’t capitalize,” Pirates manager Derek Shelton said after his team went 0 for 4 with runners in scoring position and stranded seven runners. “We were the big hit away from — I mean, understatement — but a big hit away from winning that game. We created some opportunities late in the game but weren’t able to capitalize on it.”

Right-hander Quinn Priester was on track to start, but the Pirates bumped him to Friday night at the San Francisco Giants and instead used lefty reliever Josh Fleming as an opener, with righties Luis Ortiz, Roansy Contreras, Hunter Stratton in relief.

Shelton said the back-to-back quality starts by Jared Jones and Bailey Falter allowed for the bullpen game, giving the starting pitchers an extra day of rest between outings.

“We’re going to try and build in as many days as possible for guys,” Shelton said before the game, “and the fact that we’ve had two extended starts, that makes it an easier decision.”

Fleming got good defensive plays to keep Milwaukee scoreless through the first two innings, with a 6-4-3 double play in the first and a 1-3-6 pickoff play in the second as the Pirates caught their first base stealer.

When the third started with Sal Frelick hitting a grounder to first and Rowdy Tellez making an errant throw behind Fleming covering the bag, it was a bad omen.

After Fleming walked Brice Turang, the Pirates turned to Ortiz. William Contreras singled to center to score Frelick for a 1-0 Brewers lead, then Ortiz hit Willy Adames with a pitch to load the bases. Ortiz admitted he felt “rushed” to avoid a pitch-clock violation.

With two outs, Ortiz hit Rhys Hoskins with a full-count pitch, then walked Blake Perkins on four pitches to make it 3-0 before getting Joey Ortiz looking at a called third strike to end the frame.

“We can’t hit Hoskins with the 3-2 pitch and miss by that much,” Shelton said, “but I think the one that’s a little bit frustrating is he gets Adames 0-2 and I think he was going to get a clock violation, and instead of stepping off or even taking the clock violation, he kind of rushed through it and hit him in the back with a slider. Those are things we have to avoid because they end up costing us runs.”

Luis Ortiz, who spent most of his career as a starter, refused to blame his move to the bullpen this season for his struggles with the inherited runners and command issues.

“I know my job,” Ortiz said through translator Stephen Morales. “I have to go out there, no matter what the situation and just get outs. With men on base or not, I’ve got to get outs.”

The Pirates answered in the bottom of the third, when Connor Joe drew a one-out walk and Bryan Reynolds followed by sending Bryse Wilson’s 3-1 cutter 402 feet to right-center for a two-run home run to cut it to 3-2.

Roansy Contreras gave up a pair of singles in the sixth, so the Brewers had runners on the corners when Turang attempted to steal second base. Davis made the throw to second, but Jared Triolo cut it off and threw back home to get Frelick out at the plate.

“We ran the comeback play about as well as we’ve ever seen it run,” Shelton said. “Henry was good. Triolo was good. We got a really fast runner on the backside of it.”

The Pirates made several defensive plays to save runs. Jack Suwinski made a catch against the left field wall to rob Jake Bauers in the fifth, Triolo made a diving backhand stop on a Turang single in the hole to save a run in the sixth and a leaping play to knock down Frelick’s single in the eighth.

“The importance of controlling the run game is pretty big,” Triolo said. “As we saw, it comes down to one run in a lot of these games.”

Kevin Gorman is a TribLive reporter covering the Pirates. A Baldwin native and Penn State graduate, he joined the Trib in 1999 and has covered high school sports, Pitt football and basketball and was a sports columnist for 10 years. He can be reached at kgorman@triblive.com.