CHICAGO (AP) -- Starlin Castro provided the perfect remedy for a poor start by the Chicago Cubs .
Castro had three hits, including a game-ending single in the 10th inning, and Chicago rallied past the Milwaukee Brewers 5-4 on Tuesday night.
The winning run capped a late comeback as Jeff Samardzija (5-2), the last of six Cubs pitchers, won his second straight game in relief.
"We made some mistakes early and didn't do ourselves any favors," said Chicago manager Mike Quade, whose team committed three errors. "There were about a half-dozen plays and things I saw that I'm not very happy about and they damn near cost us. But they kept playing."
Castro looped a one-out single to right off Tim Dillard (1-1) to score Tony Campana from third in the 10th.
"It was a great at-bat by (Castro) against a tough right-hander," Quade said. "He's done exactly what I needed him to do this year.
Campana opened the 10th with a double off Dillard and moved to third on Kosuke Fukudome 's sacrifice, bringing up Castro.
"Campy's got great speed, but he's got to get on base to use it," said Quade, who was ejected after loudly complaining about a pitch to Prince Fielder that plate umpire Alfonso Marquez called a ball.
Trailing 4-1, the Cubs scored three times in the eighth off Milwaukee reliever Marco Estrada . Castro doubled home Fukudome, and Aramis Ramirez followed with his fifth homer, a two-run shot that tied it 4-all.
"I don't know what's going on with (Estrada)," Brewers manager Ron Roenicke said. "Last time he pitched he had a good outing. This time, his stuff looked fine. It's down in the zone, changeup looks good, but for some reason they're hitting him well."
The rally spoiled a strong effort by Milwaukee ace Yovani Gallardo , who allowed three hits and struck out a season-high 10 in seven innings.
"I was able to mix my pitches a little better than my last start," Gallardo said. "You've just got to take that as a good thing and keep moving forward."
The Brewers, who lost the first game of the series 1-0 on Monday, dropped back-to-back games for the first time since a seven-game losing streak from April 30 to May 6.
"Today's was tough," Roenicke said. "Yesterday we didn't swing the bat, but today was a tough loss."
Milwaukee maintained a share of the NL Central lead as St. Louis lost 8-6 at Washington.
The Brewers scored twice in the third inning, sending eight batters to the plate while leaving three on base.
Rickie Weeks led off with a single and scored the first run on Ryan Braun 's base hit. The Brewers then loaded the bases and scored again when Casey McGehee grounded to shortstop for a fielder's choice that brought home Nyjer Morgan .
Starting pitcher Randy Wells then walked Corey Hart to load the bases again, but escaped the inning when Yuniesky Betancourt popped up in the infield and Jonathan Lucroy flied to left.
Fielder's one-out sacrifice fly in the fourth brought home Gallardo for a 3-0 lead.
Geovany Soto 's seventh-inning solo home run broke up the shutout bid.
Quade used five relievers over the final three innings, including rookie Chris Carpenter , who made his major league debut in the eighth.
Weeks, who had three hits, greeted Carpenter with a double to left that scored Lucroy for a 4-1 lead.
Wells worked six innings, giving up eight hits and two earned runs. He struck out two and walked three.
"We had a lot of chances to bust that game open all game," Roenicke said. "I know it came down to the bullpen, but that game we should have blown open early."
NOTES: The Cubs activated outfielder Reed Johnson from the disabled list before the game and sent OF Tyler Colvin to Triple-A Iowa. Johnson was placed on the disabled list May 29, retroactive to May 26, with lower back spasms. Colvin was batting .105 with two homers and eight RBIs. ... The Brewers are 25-9 at Miller Park, but 13-21 on the road. ... The Cubs are 9-9 in one-run games. ... Braun leads NL All-Star vote getters. He had received 2.23 million votes in figures released this week. He is seeking his fourth consecutive All-Star start.