CHICAGO — Jean Segura hit a solo homer and the go-ahead double, Khris Davis added a three-run shot, and the Milwaukee Brewers beat the Chicago Cubs 6-5 after Yovani Gallardo left with a hamstring injury in the first game of a day-night doubleheader Tuesday.

Davis' homer in the seventh on the first pitch from reliever James Russell (1-3) wiped out a 5-2 deficit, and Segura capped the four-run rally with an RBI double, giving the Brewers a 6-5 lead.

Milwaukee survived a major scare after Joe Henderson came on in the ninth. He walked a pinch-hitting Dioner Navarro and Welington Castillo, who drove a 2-0 pitch just foul beyond the left-field wall.

Henderson then retired Cody Ransom on a fly to center to give him 13 saves in 16 chances.

Segura and Yuniesky Betancourt hit solo homers as Milwaukee built a 2-0 lead, but that unraveled in the fifth.

The Cubs tied season highs with five runs and six hits in the inning, while Gallardo limped off the field with tightness in his left hamstring.

He came up clutching his leg after delivering a 1-2 pitch to Darwin Barney with two out and the bases loaded and immediately left the game.

Barney delivered a tying two-run single off John Axford, and Castillo, Carlos Villanueva and David DeJesus followed with run-scoring singles to make it 5-2.

Gallardo, whose name has come up in trade rumors, allowed three runs and six hits.

After Axford got knocked around, Rob Wooten (1-0), Brandon Kintzler and Michael Gonzalez each pitched a scoreless inning before the Cubs threatened against Henderson.

Villanueva, who gave up six hits and four runs in 6 1-3 innings for Chicago, was in line for the win after dropping his previous three starts.

He left to a nice ovation with a three-run lead and runners on first and third after Betancourt singled.

Davis, who came in as part of a double switch for Carlos Gomez in the sixth, lined Russell's first pitch out to right for the tying three-run homer.

Segura put the Brewers ahead with a double after Norichika Aoki singled with two out and stole second and third.

NOTES: Although Jeff Samardzija's name has surfaced in trade rumors, manager Dale Sveum said he thinks it's "very, very far-fetched" that he gets dealt before Wednesday's non-waiver deadline. Samardzija, 6-9 with a 3.75 ERA, is not scheduled to become a free agent until after 2015. ... RHP Scott Baker (Tommy John surgery) continued to struggle in his fourth minor league rehab start on Monday, giving up three hits and two runs in 3 1-3 innings for Class A Daytona. "I'm not too concerned because we don't have a need right now," Sveum said. ... Brewers manager Ron Roenicke said he didn't expect any deals before the deadline. ... Marco Estrada threw 2 2-3 innings Monday for Milwaukee's Arizona Rookie League team in his first appearance rehabbing from a strained left hamstring suffered June 3. Roenicke said Estrada will pitch Friday, although the location hasn't been determined, and that he'll need a minimum of two more starts before returning. ... RHP Edwin Jackson (6-11, 4.89 ERA) starts Wednesday for the Cubs, and RHP Wily Peralta (7-10, 4.54) pitches for Milwaukee.