CHICAGO (AP) Anthony Rizzo provided more power for the Chicago Cubs on Wednesday night, and they needed every bit of it when their perfect closer nearly let an easy opportunity slip away.

Rizzo homered twice, Kyle Hendricks tossed seven strong innings and the Cubs hung on to beat the San Francisco Giants 5-4 after closer Wade Davis gave up a two-run homer in the ninth inning.

Rizzo hit solo homers off Matt Moore (2-5) in the second and fourth innings for his 14th career multihomer game. He has four homers over his last four games and 11 on the season.

''I've been on some streaks sometimes, but I want to be as consistent as possible,'' Rizzo said. ''But you take it. You ride it. You ride it out and you enjoy it.''

Javier Baez made it 3-2 with a sacrifice fly in the fifth. Miguel Montero doubled and scored in the seventh, and Jason Heyward tripled and came around on Jon Jay's sacrifice fly in the eighth after the Giants left the bases loaded.

Davis allowed only one unearned run in his first 18 appearances. But things got really tight in his 19th.

Called on to start the ninth, he gave up a leadoff single to Eduardo Nunez. With one out, Mac Williamson drove a 2-2 cutter to the right-field basket on the 12th pitch of the at-bat to pull San Francisco to within 5-4.

Davis then walked Michael Morse before second baseman Baez raced back to snag Denard Span's bloop. Davis then caught Joe Panik looking at a 3-2 pitch on the outside corner. That gave Davis 10 saves in 10 chances, and the Cubs improved to 6-2 on their nine-game homestand.

Giants manager Bruce Bochy, meanwhile, made his feelings clear about the final pitch call from plate umpire Jeff Nelson.

''We had them on fumes,'' he said. ''They got the benefit of a bad call. That's not a strike, I'm sorry. But they got the call and that's it.''

Span homered for San Francisco after missing two games with a sprained left thumb. But the Giants lost for the third time in four games after winning eight of 10.

Hendricks (4-2) - 3-1 over his last six starts with an ERA of 1.96 - gave up two runs and five hits. He struck out five and walked none over seven innings, retiring 15 of the last 16 batters he faced.

''That was probably the strongest I felt deep into a game,'' Hendricks said.

Carl Edwards Jr. relieved Koji Uehara with two outs in the eighth and walked Buster Posey on four pitches to load the bases. He then fell behind 3-1 to Brandon Crawford before getting him to ground out to the mound to end the threat.

Moore gave up four runs and seven hits in six-plus innings.

STAY CLASSY, CHICAGO

The Cubs will pay homage to the Channel 4 news team by dressing as characters from the movie ''Anchorman'' on their upcoming trip to Southern California. Known for organizing wild themes for team flights, manager Joe Maddon has turned to Ron Burgundy, Brick Tamland and Brian Fantana for inspiration. The Cubs will wear the outfits Thursday when they fly out to Los Angeles, then again for the return trip from San Diego - where the comedy takes place - following a game May 31.

MINOR MOVES

The Giants promoted Chris Shaw to Triple-A Sacramento. Shaw, drafted 31st overall in 2015, was hitting .301 at Double-A Richmond with six home runs and 29 RBIs in 37 games. Shaw was originally drafted as a first baseman but this season was moved to left field, where he will play at Triple-A.

TRAINER'S ROOM

Giants: Nunez thinks he'll be able to play Thursday after experiencing some pain in his left knee. He hunched over in pain down the right-field line after beating out a bunt single in the second, but stayed in the game. ... The Giants will continue to monitor RHP Johnny Cueto, who had said he was bothered by blisters on his middle and index fingers during Tuesday's start. ''We'll continue to treat it,'' Bochy said. ''He's finding a way to get out there and pitch, and it's not a case where we're pushing it. He wants to pitch, but he is battling this and hasn't quite gotten over it.'' ... INFs Connor Gillaspie (back spasms) and Aaron Hill (right forearm strain), who are on the 10-day DL, are expected to return during the Giants' six-game homestand, which starts Friday. OF Hunter Pence (left hamstring strain) is looking at a rehab stint before his return from the 10-day DL.

Cubs: LHP Brett Anderson, who is on the 10-day DL with a lower back strain, will continue his rehab in Arizona. He threw a bullpen session on Tuesday.

UP NEXT

Giants RHP Jeff Samardzija (1-5, 4.57 ERA) and Cubs RHP Eddie Butler (1-0, 2.00 ERA) meet in the finale of this four-game series.

Copyright 2017 by STATS. Any commercial use or distribution without the express written consent of STATS is strictly prohibited.