SAN FRANCISCO — If the Giants have learned anything about a historic National League West race over the last week, it's that they can't count on any help.

The second-place Dodgers were down to their last out in Colorado last Thursday when they rallied for a game-tying ninth-inning run before winning 7-5 in 10 innings. Those same Dodgers were trailing the Padres 9-5 in the eighth inning in Los Angeles on Wednesday night when they launched four home runs, took an 11-9 lead and stunned the Padres to keep their hopes of winning the division alive.

The Giants know they'll have to take care of business on their own and while Thursday's game against the Diamondbacks was a bumpy ride, they reached their destination with a 5-4 win thanks to a walk-off single from "Late-Night" LaMonte Wade Jr.

After Wilmer Flores hit a one-out double, pinch-runner Steven Duggar scored the winning run on Wade's game-winner against Diamondbacks reliever Joe Mantiply.

A night of nostalgia for Giants fans featuring performances from Madison Bumgarner, Buster Posey, Brandon Crawford and even a cameo in the stands from Matt Cain ended in a finish that was too close for comfort for a team that entered Thursday holding a 2.0-game lead in the National League West.

Bumgarner received a standing ovation from the crowd at Oracle Park before he even took the mound as his spot in the batting order came up at the end of a three-run first inning for the Diamondbacks. Posey stepped out in front of the plate so fans could extend the ovation while Bumgarner took off his batting helmet and tipped it to the crowd, just as he did in his final plate appearance in San Francisco in 2019.

Bumgarner struck out with the bases loaded and then allowed the Giants to cut into the early Diamondbacks' lead right away as Darin Ruf doubled home Austin Slater in the bottom of the first.

The Giants added on with Posey's sacrifice fly in the second and tied the game on Crawford's 24th home run of the season in the third. The opposite-field shot Crawford hit off Bumgarner came on a 3-0 pitch and marked the first hit by a Giants player since the team returned home this week.

The Diamondbacks took another lead in the fifth inning when Kris Bryant, who has struggled as a right fielder in San Francisco, misjudged a hard line drive hit to the gap by third baseman Ildemaro Vargas. Bryant initially ran in on the ball and was unable to race back in time to reach up and make a catch.

Bumgarner would have left his outing in line to earn his 61st career win at Oracle Park with a scoreless fifth inning, but Posey spoiled it with a RBI double that he hooked just inside the third base line before rattling into the left field corner.

With Bumgarner on the mound for Arizona, the Giants turned to 37-year-old left-hander Scott Kazmir so right-handers Anthony DeSclafani and Kevin Gausman could rest an extra day before their next starts. Kazmir's start took a disastrous turn almost immediately as he walked two of the first three batters he faced with non-competitive pitches before his defense fell apart behind him.

The Diamondbacks cleanup hitter, Carson Kelly, lofted a routine flyball to shallow center field that dropped between center fielder Austin Slater and second baseman Donovan Solano after Slater failed to call off his infielder to make the catch. After another single, Kazmir induced a groundball to first baseman Wilmer Flores who chose to underhand the ball to Kazmir covering first base instead of making an aggressive throw to get a force out at the plate or take an easy out at second base with Crawford covering the bag.

Kazmir was late to cover first and injured his leg as he touched the bag, allowing a run to score and forcing Kapler to turn to rookie Kervin Castro out of the bullpen. Despite issuing a bases loaded walk that led to a run, Castro was able to keep the game close before veteran Johnny Cueto made his first career appearance out of the bullpen.

After starting each of his first 329 major league games, Cueto tossed 2 1/3 innings of one-run ball in a quest to prove he belongs on the Giants' playoff roster.