Jason Hammel held Milwaukee hitless for 5 1/3 innings, and shortstop Starlin Castro hit two home runs as the Cubs seized a 4-0 victory at Milwaukee to snap a four-game losing streak.

Hammel didn't allow a hit until Carlos Gomez ripped a double down the left field line. Gomez's hit occurred on a 1-2 pitch immediately after catcher John Baker visited the mound.

Scooter Gennett drew a walk, and the runners moved up on an errant pickoff throw by Hammell at second. But Hammel struck out Jonathan Lucroy on a 94 mph fastball and Aramis Ramirez on a grounder to third.

Hammel pitched seven-plus innings of three-hit ball. His ERA dropped to 2.08, and he has allowed only 17 hits in 34 2/3 innings.

The first batter to reach base safely was opposing pitcher Wily Peralta, as Castro sailed a throw past first baseman Anthony Rizzo for a two-base error with two out in the third.

Castro has led the way for the Cubs at the plate with a home run over the center field fence that ignited a two-run second inning, and he hit a line drive that cleared the left field fence in the eighth.

Nate Schierholtz snapped out of an 0-for-14 slump with a single, and Baker snapped an 0-for-18 slump to start the season with an infield hit to load the bases. Darwin Barney drove in the Cubs' second run on a fielder's choice.