Wesneski (2-1) gave up two runs and five hits in 6 1/3 innings while striking out six and walking two in sending Pittsburgh to its seventh straight loss. It was his fourth appearance in the majors.
Wesneski had an immaculate inning in the fifth when he struck out the side on nine pitches. He fanned the three hitters at the bottom of the order: Jack Suwinski, Zack Collins and Jason Delay.
''It's crazy,'' Wesneski said. ''You start thinking about it about the seventh, eighth pitch, then on the ninth pitch you've got to let it rip and make it happen. I've been a part of one in college (at Sam Houston State) but this one is a lot different.''
It was the 111th immaculate inning in major league history and fourth in Cubs history. The last Cubs pitcher to accomplish the feat was LaTroy Hawkins in 2004.
''I've never been a part of an immaculate inning, so that's really cool,'' said Cubs manager David Ross, who was a major league catcher for 15 seasons. ''The pitching guys in the dugout were all happy. There were a lot of high-pitched voices.''
In his first start against Colorado last Saturday, Wesneski pitched one-run ball over seven innings in a no-decision. The Cubs acquired him from the New York Yankees in a trade Aug. 1.
Wesneski had to ask a security guard where to find the visiting bullpen Thursday before warming up but then was sharp again.
''There is a lot of preparation that goes into it, plus I have two great catchers and a great staff on top of it,'' Wesneski said. ''I'm just one a roll right now. I did this last year (in the minor leagues). Once you get in a rhythm, it makes it a little easier, but the biggest thing is commanding the fastball and I've been doing that this year for the most part.''
Mark Leiter Jr. got the last seven outs for his third save. The Pirates put the runners on second and third with two outs in the ninth, but Rodolfo Castro lined out to center field to end the game.
Christopher Morel hit a two-run double, and David Bote and Michael Hermosillo had two hits for the Cubs, who won their third straight game.
Mitch Keller (5-12) pitched well in a losing effort, allowing two runs and four hits in six innings. He struck out seven and walked two.
Keller has yielded three earned runs or fewer in 17 of 20 starts since being moved back to the rotation May 31 following a brief demotion to the bullpen.
Bryan Reynolds was 3 for 3 with an intentional walk for the Pirates. Kevin Newman homered.
Morel's double down the left-field line with two outs in the second inning opened the scoring.
''After the second inning, I kind of went in the dugout and just told myself I just needed to be more aggressive,'' Keller said.
The Pirates cut the lead in half on Reynolds' RBI single in the third inning.
Hermosillo's run-scoring single in the seventh restored the Cubs' two-run lead. The Pirates countered with a leadoff home run by Newman in the bottom half of the inning to draw within a run.
The start of the game was delayed 25 minutes because of rain and momentarily in the seventh inning when the stadium lights went out.
SUZUKI STILL AWAY
Cubs outfielder Seiya Suzuki is expected to remain on the restricted list throughout the four-game series that ends Sunday. He and his wife continue to await the birth of their first child.
Suzuki was moved from the paternity list to the restricted list Thursday in a procedural move. The Cubs signed him to a five-year, $75-million contract as a free agent March after he starred in his native Japan.
BEDNAR IS BACK
The Pirates activated RHP David Bednar, their lone All-Star this season, from the injured list, before the game and he allowed one run in one inning of relief. He had been out since July 30 with lower back inflammation.
Bednar has 17 saves in 21 opportunities.
''We're definitely in a good spot right now,'' he said. ''We're feeling better, so hopefully we'll just finish out the season strong and go into the offseason feeling healthy.''
Cubs: SS Nico Hoerner (strained triceps) missed his 10th straight game, but the team has opted not to place him on the IL.
Pirates: LHP Eric Stout (lower back discomfort) was placed on the 15-day IL, which ends his season.
Cubs: Rookie RHP Javier Assad (1-2, 3.86) will start Friday night. He lasted just two innings in his previous start last Sunday against Colorado, allowing four runs and taking the loss.
Pirates: RHP Bryse Wilson (3-9, 6.07) is 1-3 with a 6.48 ERA in his last seven games, including six starts.
More AP MLB: https://apnews.com/hub/mlb and https://twitter.com/AP-Sports
Copyright 2022 STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.