SAN DIEGO — The Giants and Dodgers played their last head-to-head matchup of the season on Sunday, Sept. 5, but given the historic nature of the race for the National League West crown, each day feels as if the rivals are squaring off against one another.

If 19 back-and-forth games between the Giants and Dodgers this season were any indication of what’s in store for the final days of the schedule, then Thursday’s dramatic finishes for both clubs were hardly a surprise.

The Giants rallied from a pair of deficits against the Padres on Thursday, but lost 7-6 in 10 innings on a walk-off infield single from Victor Caratini against right-hander Dominic Leone. The Dodgers, meanwhile, took a bite out of San Francisco’s division lead by winning 7-5 in 10 innings over the Rockies at Coors Field.

Brandon Belt and Kris Bryant each found themselves ahead in the count 3-0 against Padres lefty Ross Detwiler with a runner in scoring position in the 10th inning, but both players ended up popping out before the Giants saw their lead in the NL West shrink to one game with nine left to play following the Padres’ walk-off.

“I’ll take our chances with Brandon Belt 3-0 and then subsequently 3-1 count and then Kris Bryant in the same situation against a pitcher, who obviously no disrespect, wasn’t at his best,” manager Gabe Kapler said. “Unfortunately, we weren’t able to cash that in.”

Shortly after the Dodgers jumped out to a 3-0 lead over the Rockies with leading Cy Young candidate Max Scherzer on the mound, the Giants fell behind the Padres 4-0 as ace Logan Webb struggled through a 45-pitch first inning.

The Giants, like the Rockies, were able to cut into their opponent’s lead as Mike Yastrzemski launched a two-run home run off Padres starter Yu Darvish while Colorado pitcher Kyle Freeland hit a game-tying, two-run single to even the score at 3-3 against Scherzer.

When Austin Slater stepped up and yanked a go-ahead three-run home run in the top of the sixth, the Giants could look up at the out-of-town scoreboard and see that the Rockies were one out away from securing an unlikely series victory over the Dodgers.

“Our focus was solely on this game, this is a good team across the other side of the field,” Slater said. “But they flash the scores and it’s hard to miss sometimes. You’re aware of it.”

Despite having the bases empty with two outs in the ninth, the Dodgers strung together three hits and a run, forcing their game into extra innings just as the Padres hit back-to-back homers to give San Diego a 6-5, sixth-inning lead. Within a minute of Dodgers star Max Muncy giving Los Angeles the lead for good with a two-run, 10th inning homer, Giants pinch hitter Wilmer Flores and second baseman Tommy La Stella struck back-to-back doubles to tie the game at Petco Park.

Slater had only hit one home run since the All-Star break when he came off the bench in the sixth to bat for LaMonte Wade Jr., one of the top clutch hitters in the majors this season. Despite falling behind in the count 1-2 against Padres lefty Tim Hill, Slater battled back by hitting three foul balls and taking two more pitches off the plate before lining a three-run, go-ahead home run over the short left-field wall in front of the Western Metal Supply Co. building.

Slater’s pinch homer was the 17th hit by a Giants player this season, matching the major league record set by the 2016 St. Louis Cardinals and giving the club a chance to capture another comeback win.

“Pinch hitting is one of the harder things in sports, but the more you do it, the more comfortable you get with your routine and what you need to do to get ready,” Slater said.

With most of their top relievers unavailable, the Giants weren’t able to protect the one-run lead for long.

In the bottom of the sixth, the Padres answered right away with back-to-back solo home runs from Trent Grisham and Ha-Seong Kim, who pushed San Diego ahead 6-5 against left-hander José Quintana. A Giants offense that’s been unfazed in the late innings this season rallied to even the score, and then the club received quality work out of the bullpen from 22-year-old Kervin Castro, who tossed 1 1/3 scoreless innings to send the game to the ninth inning tied at 6-6.

Webb has easily been the Giants’ best pitcher through the second half of the season, but he suffered through a disastrous first inning on Thursday as his command evaded him against a Padres lineup that was able to score four runs on just three hits.

“I couldn’t tell you what was going on in the first inning, I’d have to go and watch it again,” Webb said. “I was a little frustrated, I won’t elaborate on that, but I let it spiral.”

Webb threw more balls than strikes in his opening frame against San Diego as the right-hander issued two walks before hitting right fielder Jurickson Profar with a slider on an 0-2 pitch with the bases loaded. Following a sacrifice fly from Grisham and RBI singles from Kim and Caratini, the Padres took a 4-0 lead as Webb fell into the type of early hole he’s largely avoided during a remarkable run of post-All-Star break success.

“It was sort of unusual to see him come out and miss as big as he was missing given how good he has been in the strike zone for several months,” Kapler said.

Kapler was one baserunner away from turning to Quintana, but Webb struck out Darvish to end the first and returned to the mound in the second inning despite having already thrown so many mostly high-stress pitches.

At a different point in the season, Kapler may have pulled Webb following the first inning, but with a depleted bullpen and a three-game series at Coors Field upcoming, the Giants stuck with the 24-year-old right-hander. The decision to do so paid off as Webb regained the consistency he’s shown for most of the season and fired three scoreless frames to keep the Giants in the game.

Their lineup brought the Giants all the way back, but an inability to drive a run home in the top of the 10th wound up costing the club. A day that easily could have ended with the Giants ahead by three games in the NL West finished with the Dodgers cutting the lead down to one game.

“They’ve been right there pretty much the whole season,” Slater said. “This isn’t really anything new for us.”