CHICAGO (AP) — After watching the Cubs waste a couple of leads, Kris Bryant felt a loss was almost inevitable.

That quickly changed with one swing by the Chicago slugger.

Bryant hit a go-ahead, two-run homer in the eighth inning to give the Cubs a 12-11 comeback victory over the San Francisco Giants in a wild, back-and-forth game Wednesday night at Wrigley Field.

“This is one of those games where you don’t feel like you’re going to win because you’re taking a lead and giving it back,” Bryant said. “But we came out on top, and definitely some good momentum here.”

Nicholas Castellanos and Kyle Schwarber also connected for Chicago, which has won four straight. The Cubs moved back into first place in the NL Central by a half-game over St. Louis, which lost to Milwaukee in a rain-shortened game.

Castellanos, who went 4 for 5, has homered in three consecutive games for the second time in his career — he also did it with Detroit in 2016 — and has eight in 19 games since being acquired in a trade before the July 31 deadline. He is batting .392 (31 for 79) with the Cubs.

Evan Longoria, Mike Yastrzemski, Stephen Vogt and Kevin Pillar homered for San Francisco, which has dropped three in a row.

Castellanos led off the eighth with an infield single to set the stage for Bryant, who stroked a 1-1 pitch from Reyes Moronta (3-7) into the left field bleachers.

Brandon Kintzler (3-2) pitched a scoreless inning and Craig Kimbrel worked a 1-2-3 ninth for his 11th save.

“That’s a tough one for us,” Giants manager Bruce Bochy said. “You get that many runs, that kind of production … those are games that we’ve been winning, and this one got away from us.”

Cubs starter Yu Darvish tossed seven sharp innings against Philadelphia in his last outing and left with a 5-0 lead. But the bullpen blew the big advantage, leaving the right-hander with a no-decision.

Chicago led 6-2 heading into the fifth on Wednesday. This time, Darvish coughed up the lead himself.

After retiring 12 straight batters, he gave up a double to Brandon Crawford with one out in the fifth. One out later, Yastrzemski homered to make it 6-4.

The Cubs got a run back in the bottom half, but San Francisco scored five in the sixth to take the lead.

Darvish, after dropping a routine throw from Anthony Rizzo at first base for an error with one out, gave up a two-run homer to Vogt that made it 7-6. Pillar followed with a solo shot to tie the score.

That was all for Darvish, who allowed seven runs (six earned) and seven hits in 5 1/3 innings. He had eight strikeouts and walked none for a career-high fifth straight start.

Derek Holland took over in the sixth against his former team and didn’t fare any better. He gave up three hits in two-thirds of an inning, including a two-run double to pinch-hitter Austin Slater that gave the Giants a 9-7 lead.

The Cubs rallied for three runs in the bottom half against reliever Trevor Gott to grab a 10-9 advantage. Rizzo drove in the first with a double to left-center, Javier Báez tied the game with an infield single and Schwarber drove in the go-ahead run with a groundout.

San Francisco scored twice in the seventh to grab an 11-10 lead.

Bryant believes this is a game to build on for the Cubs.

“We were high-fiving there and Riz told me, ‘This is a season-defining win,'” he said. “I can’t disagree with him.”

TRAINER’S ROOM

Giants: RHP Shaun Anderson (blister) allowed two hits with four strikeouts over 3 1/3 scoreless innings in a rehab start for Triple-A Sacramento on Tuesday. … RHP Johnny Cueto (Tommy John surgery) made his fourth rehab appearance for Class A San Jose on Tuesday, allowing five runs (four earned) and four hits with three strikeouts in 4 1/3 innings. “He threw fine; he feels great,” Bochy said. “He’s going to throw Monday for Sacramento.”

Cubs: Projected closer Brandon Morrow is out for the year following another setback in his recovery from right elbow surgery. Morrow had the arthroscopic procedure last November and hasn’t pitched since July 2018. “He certainly worked really hard in an attempt to come back and tried a lot of different techniques and procedures, and just wasn’t able to get over the hump,” team president Theo Epstein said.

UP NEXT

Giants RHP Jeff Samardzija (9-9, 3.54 ERA) faces his former team in the finale of the three-game series Thursday afternoon. Samardzija is 0-2 with a 6.35 ERA in three starts against Chicago. RHP Kyle Hendricks (8-9, 3.37) pitches for the Cubs.

___

More AP MLB: https://apnews.com/MLB and https://twitter.com/AP_Sports