San Francisco >> Ryan Walker has had a rough week. Patrick Bailey has had rough month. On a day where the Giants honored honored the legacy of Brandon Crawford, Bailey and Walker ensured the good vibes carried on into the evening.

Walked pitched out of a jam in the top of the ninth and Bailey delivered a pinch-hit, walk-off single in the bottom of the ninth as the Giants beat the Texas Rangers, 3-2.

“Just trying to get a pitch to do the job,” Bailey said. “Not trying to get too big, just move the ball.”

San Francisco and Texas entered the ninth inning tied up at two, but the game had been tilting in the Giants’ favor following Willy Adames’ two-run, game-tying single in the bottom of the fifth inning, a swing that extended his hitting streak to five games. The Rangers established an early 2-0 lead by scoring a run apiece off Robbie Ray in the first and third, but Ray saw an uptick in velocity from the fourth inning onwards and delivered seven innings of two-run ball with eight strikeouts.

Walker allowed back-to-back singles to start the top of the ninth, evoking memories of his outings against the Los Angeles Angels and Milwaukee Brewers earlier this week when he allowed six total runs and recorded one total out. With little margin for error, Walker retired the next three batters he faced and delivered a scoreless inning, setting up an opportunity for the offense to deliver a win.

“I think today was a big step for him,” Ray said. “I was in (the clubhouse) watching it on the TV. They get the two singles, then he kind of locked it in and took it to a different level. It was good to see that. His slider was sharp today. Even the hits they got, they were on good pitches. … For him, it’s a little bit of a confidence boost right there. Being able to get out of that is huge for us.”

One of those three batters that Walker retired was two-time All-Star and former Giant Joc Pederson. Despite entering play with a .078 batting average, Walker knew Pederson was capable of flipping the game with one swing. Manager Bob Melvin had left-hander Erik Miller warmed in the bullpen, but elected to stick with Walker since Rangers manager Bruce Bochy would likely counter with Adolis García.

Walker allowed a long foul ball to Pederson, but rewarded Melvin’s faith by striking out Pederson swinging to end the inning. Walker, typically mild-mannered, emphatically roared as he walked off the mound, a response to the struggles he hopes he has overcome.

“The last week, all that stuff just boiling up and finally finding a groove — hopefully — brought out all that emotion,” Walker said. “And it’s fun to play like that, too. Really get into it.”

Walker’s scoreless inning in the top of the ninth set the stage for the Giants to win the ballgame in the bottom of the ninth. Facing the Rangers’ Jacob Webb, Heliot Ramos began the frame with a leadoff single, then LaMonte Wade Jr. followed up with a walk. Christian Koss laid down a perfect sacrifice bunt to advance the Ramos and Wade, putting runners on second and third with one out.

Melvin pinch-hit Sam Huff — the former Ranger — for Bailey; Bochy countered by bringing in left-handed reliever Jacob Latz. The lefty’s outing lasted all of one pitch. With first baseman Jake Burger shifted to the right, Bailey flipped a soft line drive into right field that easily scored Ramos, delivering the Giants their fourth walk-off win of the season and the fourth walk-off hit of his career.

Bailey’s struggles have not been as extreme as Walker’s, but the Gold Glove Award winner has scuffled at the plate to begin the season. Entering play, Bailey’s .460 OPS ranked last on the Giants and was hitting 70 percent worse than a league-average hitter. Bailey’s numbers still leave more to be desired even with the walk-off, but Bailey said he’s been encouraged by his recent at-bats.

“I feel like the last week, my swings from both sides have felt better and better,” Bailey said. “Just trying to swing at the right pitches and go from there.”