Dodgers’ postseason hopes on the line in series vs. Giants.

SAN FRANCISCO — The San Francisco Giants get an opportunity to play spoiler against the team they’d most enjoy spoiling — the Los Angeles Dodgers — when the longtime rivals close out the regular season with a three-game series that begins Friday night.

Giants ace Madison Bumgarner (6-6, 3.20 ERA), the star of his last AT&T Park appearance with his bat, is scheduled to duel Dodgers left-hander Hyun-Jin Ryu (6-3, 2.00), who pitched brilliantly the last time he faced San Francisco.

The Dodgers (88-71) enter the series with a chance to win the National League West, capture an NL wild card or miss the playoff entirely, all to be determined within three games against a team that has beaten them nine of 16 this season.

LA will take the field Friday night one game behind the Colorado Rockies (89-70) in the West, and one game ahead of the St. Louis Cardinals (87-72) in the wild-card race. The Rockies host the Washington Nationals on Friday night, and the Cardinals begin a three-game series against the Chicago Cubs at Wrigley Field.

The Cubs, Milwaukee Brewers and Atlanta Braves have all already clinched playoff spots in the NL.

“Not how we scripted it,” Dodgers manager Dave Roberts said after Wednesday’s second consecutive loss to the Arizona Diamondbacks, which dropped LA into second place.

“We’re a very dangerous team. I know we believe in ourselves. Now our focus has to turn to the Giants.”

Ryu has been the Dodgers’ hottest pitcher of late, coming off back-to-back shutout efforts covering a total of 13 innings against Colorado and San Diego. He has allowed just eight hits in those two wins.

The 31-year-old has faced the Giants 14 times in his career, going 4-6 with a 3.09 ERA. He’s 4-3 with a 3.38 ERA in eight starts in San Francisco.

Evan Longoria and Brandon Crawford homered against Ryu in an earlier meeting this season at AT&T Park, a game the Giants won 6-4 in April. But Ryu got a measure of revenge in an Aug. 15 start in LA, pitching six innings of three-hit, shutout ball.

He’ll be facing a Giants team that has been out of playoff contention for more than a month. They’ve lost six of their last seven, including a three-game sweep last week at the hands of the Cardinals, who gained ground on the Dodgers in the process.

Joe Panik, who began the season with consecutive game-winning home runs against the Dodgers, believes the Giants still have some fight in them.

“We’re all playing for pride, for the Giants name on the front of the jersey,” he said after Wednesday’s 3-2 home loss to San Diego. “The rivalry with the Dodgers, having them at home, they’ve got these games on the line … that’s going to give us a little extra incentive to lay it all out there.”

Bumgarner beat the Dodgers 5-2 on Aug. 13, allowing a home run to Justin Turner among seven hits in six innings.

He also lost a 3-1 decision in LA in June when Matt Kemp and Enrique Hernandez took him deep.

Bumgarner has more career wins against the Dodgers (15) than any other team. He has gone 15-10 with a 2.61 ERA in 31 meetings, including 30 starts.

The respected hitter was last seen pinch-hitting in the 12th inning against the Padres on Tuesday night. He delivered his first career walk-off hit, a single that ended a 5-4 win.

Bumgarner has gone 2-for-10 with four strikeouts in his career against Ryu.