SAN FRANCISCO (AP) — LaMonte Wade Jr. singled home the winning run with one out in the ninth inning and the San Francisco Giants held their two-game lead in the NL West, beating the Arizona Diamondbacks 5-4 on Thursday night.

The Giants posted their 105th victory — one off the franchise record set in 1904 — and kept their edge over the second-place Los Angeles Dodgers going into the final weekend of the season.

San Francisco closes with three games at home against San Diego. The Dodgers finish with three at home against NL Central champion Milwaukee.

On a night when former Giants star Madison Bumgarner settled for a no-decision pitching against his former club back in San Francisco for the first time in front of cheering fans, Wade drew the final ovation.

With the score tied at 4, Wilmer Flores hit a one-out double in the ninth off Joe Mantiply (0-3), who then intentionally walked Donovan Solano. A walk to pinch-hitter Curt Casali loaded the bases for Wade.

Tyler Rogers (7-1), San Francisco's sixth reliever, pitched two innings for the win.

Johnny Cueto entered in relief after coming off the injured list earlier in the day and pitched 2 1/3 innings for the Giants, allowing one run and three hits with three strikeouts.

Ildemaro Vargas hit a go-ahead triple in the Arizona fifth before Buster Posey's double in the bottom half made it 4-all.

Brandon Crawford homered in the fourth off his former longtime teammate MadBum, who helped the Giants win championships in 2010, ‘12 and ’14 — Bumgarner was the World Series MVP that last time.

Posey hit a sacrifice fly against Bumgarner in the third.

Bumgarner was recognized at Oracle Park in August but didn't pitch that series. He did face the Giants on his old mound during the coronavirus-shortened 2020 season but with cardboard cutouts in the stands instead of real people.

The star lefty allowed eight hits and four runs over five innings, struck out four and didn't walk a batter. He hasn't won since Aug. 19 against the Phillies, going 0-3 over his last seven outings.

Bumgarner drew a warm ovation during pregame introductions, then again when he stepped into the batter's box in the first and before he threw his first pitch.

“I hope it's a good moment for him. I think it's going to be pretty cool, first time I think this place is going to be packed,” Giants pitcher Kevin Gausman said. “We gave him a pretty good reception earlier this year when he came here but he didn't pitch. I thought that was pretty impressive. He's probably going to get a pretty substantial ovation, and for good reason. What he did here, especially that one year, he essentially won them the World Series. He was unbelievable all year.”

Bumgarner signed an $85 million, five-year contract with Arizona after the 2019 season and 11 years with the Giants.

Austin Slater greeted Bumgarner with a leadoff single and Darin Ruf followed with an RBI double.

Carson Kelly and Pavin Smith hit RBI singles in the fourth straight defeat for the D-backs (50-109), who finished with a 20-61 road record that included a record 24-game skid away from Chase Field.

Arizona went 0-9 at San Francisco this season and is two losses from the franchise record of 111 in 2004.

After Crawford's dazzling stop at shortstop on Ketel Marte's grounder leading off the game, Scott Kazmir issued back-to-back walks before three straight singles.

Kazmir exited his fourth start and fifth appearance after recording just one out, injured when he hustled to cover first on an infield single. Kervin Castro relieved and issued a bases-loaded walk that made it 3-0.

TRAINER'S ROOM

Giants: Cueto will be used out of the bullpen for now after dealing with elbow issues this year. “I’ll be myself," Cueto said. "Of course, I’ll be a little bit more aggressive because I know it’s going to be maybe one inning or two.”... Ruf also was activated from the IL and back in the lineup playing left field batting second. ... LHP Tony Watson was placed on the 10-day IL retroactive to Wednesday with a strained pitching shoulder.

ROSTER MOVE

The Giants designated LHP José Quintana for assignment.

UP NEXT

Diamondbacks: Will send RHP Humberto Castellanos (2-2, 4.28 ERA) to the mound Friday night back at home against Colorado for his seventh start and 14th appearance of the year.

Giants: RHP Anthony DeSclafani (12-7, 3.26) pitches Friday night's series opener against San Diego seeking just his second win in eight starts since Aug. 13.

___

More AP MLB: https://apnews.com/tag/MLB and https://twitter.com/AP_Sports