Wilmer Difo had three hits and drove in three runs as the Pirates won for just the third time in their last 20 games at Wrigley Field.
Held to two runs and four hits by Anderson (3-3), the Cubs made it close in the ninth.
Reliever Kyle Crick hit Anthony Rizzo with a pitch and walked Kris Bryant before getting David Bote on a flyout. Richard Rodríguez took over and gave up an RBI single to Joc Pederson singled with two outs that made it 6-3.
Ildemaro Vargas hit a two-run double, but Rodriguez retired pinch-hitter Javier Báez on a grounder to end it for his sixth save.
Kyle Hendricks (2-4) allowed six runs — four earned — and nine hits in five innings.
Anderson struck out six and walked one to beat the Cubs for the first time in three starts this season. He retired his final 13 batters.
Pederson had three hits for the Cubs, who were trying for their first undefeated homestand of at least six games since August 2015, when they beat San Francisco in four games and Milwaukee in three.
The Pirates scored four times in the first. Jacob Stallings had an RBI grounder with the bases loaded, Difo hit a two-run single off Hendricks and Vargas made a throwing error from shortstop.
Difo added an RBI triple and another run scored on third baseman Matt Duffy’s error for a 6-1 lead in the third. Hendricks threw a seven-inning complete game win over the Los Angeles Dodgers on Tuesday in his last start.
Pirates: INF Colin Moran (left groin strain) went on the 10-day injured list after he exited Saturday’s game against the Cubs in the first. He was injured after he caught a liner and dived to first base trying to complete a double play. … OF Bryan Reynolds (lower body soreness) was out for rest.
Cubs: OF Jake Marisnick (right hamstring strain) exited Sunday’s game in the first inning after he was injured attempting to field a single. … SS Báez (stiff back) was out of the starting lineup for rest after he left Saturday’s game after the seventh inning. He pinch hit in the ninth. … RHP Jake Arrieta (right thumb) is expected to be ready for next weekend’s series at Detroit, manager David Ross said. Arrieta threw a bullpen Saturday and will throw another this week in Cleveland.
Sanchez, Voit lift Yankees to walk-off win
Gary Sanchez belts a solo home run to tie the game and then Luke Voit's big single sends the Yankees to a 6-5 walk-off win vs. the Royals.
Lindor, Conforto, new pitchers lead Mets past Braves 7-3
— Francisco Lindor homered and drove in three runs, Michael Conforto jolted New York's stagnant offense in his delayed return from injury and the Mets beat the Atlanta Braves 7-3 on Wednesday night.
Sánchez, Voit lift Yankees over Royals 6-5 in thriller
— Gary Sánchez homered off Greg Holland in the ninth inning, Luke Voit hit a winning single and the New York Yankees survived another blown save by Aroldis Chapman to beat the Kansas City Royals 6-5 on Wednesday night.
García extends rookie HR lead to 20 as Rangers beat A's 5-3
— Major league rookie home run leader Adolis García went deep twice for his 19th and 20th, Brock Holt had a tiebreaking RBI single in the seventh inning and the Texas Rangers beat the Oakland Athletics 5-3 on Wednesday night.
Lindor cranks his ninth HR with the Mets
Francisco Lindor provides the Mets with some vital insurance runs with a two-run shot in the second inning.
Rays stop 7-game skid, beat AL East-leading Red Sox 8-2
— Austin Meadows, Mike Zunino and Brandon Lowe homered to help the Tampa Bay Rays stop a seven-game losing streak by beating the AL East-leading Boston Red Sox 8-2 on Wednesday night.