CHICAGO — It was a familiar feeling for Jeff Samardzija. He pitched before a charged crowd at Wrigley Field, and his team lost.

Samardzija lasted just four innings in his first start as a visitor at the famed ballpark and the bullpen gave away the lead in the seventh, with Addison Russell hitting a two-run single to lead the Chicago Cubs to a 5-4 victory over San Francisco on Thursday night.

“It was an exciting atmosphere and reminded me a lot of my earlier years here when we were filling it up and everyone was excited,” said Samardzija, who gave up three runs and five hits. “It was a little different being on the other side, but it was fun.”

Samardzija was a rookie in 2008 when the Cubs won the NL Central. But for much of his time in Chicago, he played for a losing team that finally experienced a huge payoff for a painful rebuild after it traded him away.

The Giants are trying to lock down a playoff spot and rediscover the touch that gave them the best record in baseball at the All-Star break. Since then, they are a major league-worst 15-28.

The Cubs, on the other hand, started September on a winning note after going 22-6 to match the 1932 team for the best August in franchise history.

The major league leaders also moved a season-high 39 games over .500 and a jaw-dropping 15 1/2 games ahead of St. Louis in the NL Central — their largest lead in the standings since the 1907 team finished 17 games ahead of Pittsburgh, according to the Elias Sports Bureau.

Russell’s bloop single off Cory Gearrin gave the Cubs a 5-4 lead. Dexter Fowler had two singles and scored two runs.

Kris Bryant added an RBI single to extend his hitting streak to 14 games, matching a career high. And the Cubs rallied behind a dominant bullpen and another big hit by Russell.

The 22-year-old Russell’s 88 RBIs are tops among National League shortstops. He is 8 for 18 and has driven in 23 runs with the bases loaded. On top of that, he is playing a Gold Glove-level defense.

His go-ahead hit wiped out a 4-3 deficit and capped a rally that began when Hunter Strickland (3-2) gave up a leadoff single to Fowler and walked Bryant after two close pitches were called balls.

Will Smith walked Ben Zobrist with one out to load the bases before retiring Jason Heyward on a pop fly. But Russell then drove in Fowler and Bryant with a bloop single to left.

“It obviously felt like I had a good game plan,” Gearrin said. “Made two good pitches and broke his bat and he just found a hole. It’s just frustrating because you want to get the result no matter what. At the same time as a pitcher, you can only do so much.”

Russell’s hit made a winner of Joe Smith (2-4), who worked two innings after returning from a strained left hamstring.

Carl Edwards Jr. worked the ninth for his first career save with Aroldis Chapman getting the night off after pitching in the previous three games. And the Cubs came away with the win on a cool and windy night in which both starting pitchers lasted just four innings.

SHAKY STARTS

Samardzija walked three and threw 87 pitches in his second start against Chicago and first as a visitor at Wrigley Field. The right-hander played for the Cubs until he was traded to Oakland during the 2014 season in the deal for Russell.

Chicago’s Mike Montgomery gave up four runs — three earned — and three hits, including a long two-run homer to Hunter Pence in the first.

TRANSACTIONS

The Giants reinstated LHP Josh Osich and OF Mac Williamson from the DL and recalled LHP Ty Blach, LHP Matt Reynolds, LHP Steven Okert and INF Kelby Tomlinson from Triple-A.

TRAINER’S ROOM

Giants: RHP Matt Cain (lower back strain) is expected to come off the DL and head to the bullpen rather than the rotation. Manager Bruce Bochy said the three-time All-Star, who has struggled with injuries in recent seasons, was “all for” the assignment. RHP Albert Suarez will start Friday.

Cubs: RHP John Lackey (strained right shoulder) will likely return to the rotation this weekend. Thursday’s throwing session went well, and assuming no setbacks, the veteran will start Sunday.

UP NEXT

The Cubs send LHP Jon Lester (14-4, 2.70 ERA), unbeaten in his past six starts, to the mound while Suarez (3-2, 4.35) makes his eighth start for San Francisco.