Los Angeles Dodgers' Yasiel Puig, right, is tagged by San Francisco Giants catcher Nick Hundley after striking out during the first inning of a baseball game in San Francisco, Tuesday, Sept. 12, 2017. (AP Photo/Jeff Chiu)

San Francisco Giants' Kelby Tomlinson, right, crosses the plate next to Los Angeles Dodgers catcher Yasmani Grandal after hitting a solo home run during the third inning of a baseball game in San Francisco, Tuesday, Sept. 12, 2017. (AP Photo/Jeff Chiu)

Los Angeles Dodgers pitcher Clayton Kershaw walks in front of the mound after allowing a home run to San Francisco Giants' Kelby Tomlinson, rear, during the third inning of a baseball game in San Francisco, Tuesday, Sept. 12, 2017. (AP Photo/Jeff Chiu)

Los Angeles Dodgers' Yasiel Puig (66) reacts after hitting two-run double against the San Francisco Giants during the fourth inning of a baseball game in San Francisco, Tuesday, Sept. 12, 2017. (AP Photo/Jeff Chiu)

Former NFL quarterback Joe Montana throws out the ceremonial first pitch before a baseball game between the San Francisco Giants and the Los Angeles Dodgers in San Francisco, Tuesday, Sept. 12, 2017. (AP Photo/Jeff Chiu)

San Francisco Giants pitcher Johnny Cueto throws to a Los Angeles Dodgers batter during the second inning of a baseball game in San Francisco, Tuesday, Sept. 12, 2017. (AP Photo/Jeff Chiu)

Los Angeles Dodgers pitcher Kenta Maeda, left, shakes hands with IndyCar driver Takuma Sato before a baseball game between the San Francisco Giants and the Dodgers in San Francisco, Tuesday, Sept. 12, 2017. (AP Photo/Jeff Chiu)

Los Angeles Dodgers pitcher Clayton Kershaw throws to a Francisco Giants batter during the first inning of a baseball game in San Francisco, Tuesday, Sept. 12, 2017. (AP Photo/Jeff Chiu)

Los Angeles Dodgers' Chase Utley (26) is congratulated after hitting a solo home run against the San Francisco Giants during the fourth inning of a baseball game in San Francisco, Tuesday, Sept. 12, 2017. (AP Photo/Jeff Chiu)

SAN FRANCISCO (AP) — Mired in an 11-game losing streak, Clayton Kershaw and the Los Angeles Dodgers felt the magnitude of this regular-season game more than most.

And understandably so, the way September has gone so far.

Kershaw pitched the Dodgers to their first win in nearly two weeks, helping them clinch a playoff berth by finally beating the San Francisco Giants 5-3 on Tuesday night to snap the club's longest slide since moving to the West Coast in 1958.

"We needed it," manager Dave Roberts said. "We were scratching and clawing to get that W."

The Dodgers' drought was their worst in 25 years, topping 10-game skids in Los Angeles during the 1961 and 1992 seasons. The 1944 Brooklyn team lost 16 straight games.

Despite the recent tailspin, Los Angeles still owns the best record in the majors at 93-52. The NL West leaders won for just the second time in 18 games and secured at least the second NL wild card, joining the NL East champion Washington Nationals as the only teams to punch their postseason tickets so far.

"A lot of relief in that clubhouse," Roberts said. "Usually there's handshakes but tonight there were more hugs. Playing it cool went to the side tonight. I think it was warranted."

Kershaw (17-3) tossed six innings and tied Milwaukee's Zach Davies for the major league lead in wins.

Kenley Jansen got four outs for his 37th save but allowed three straight singles with one out in the ninth to face a bases-loaded jam. He struck out Buster Posey and Nick Hundley to end it. Los Angeles catcher Yasmani Grandal pumped his right fist and Jansen pounded his chest as the Dodgers hustled out of their dugout.

"He's the best in the league for a reason. He got it done," Kershaw said of the Dodgers' closer. "Tonight wasn't easy. Nothing about these past two weeks has been easy so we shouldn't have expected this one to be easy. ... We needed everybody to get a win tonight. It took just about everybody. More just a sense of relief now that we got a win. We can't let up. Every time the losses keep mounting and mounting it gets that much harder to win a game."

Justin Turner hit a key RBI double in the eighth and Chase Utley homered leading off the fourth, splashing into the water of McCovey Cove beyond the right-field wall for the first time in his career — the 41st ever by an opposing hitter.

Neither team took batting practice on the field after playing past 2 a.m. because of two delays for lightning and rain Monday.

Los Angeles, which won for the first time since topping San Diego on Sept. 1, holds a 4 1/2-game lead over Washington for the best record in the National League after the Nationals lost 8-0 to Atlanta. The teams meet this weekend in D.C.

"Making the postseason's no small feat," Kershaw said. "Can't take that for granted, but from where we've been we want home field, we want the division, we want home field throughout the World Series. We have a lot of things to keep going for."

Kershaw followed Utley's homer with a double and Corey Seager put the Dodgers ahead on a sacrifice fly. Yasiel Puig's two-run double chased Johnny Cueto, who had intentionally walked Cody Bellinger to bring up Puig.

Kelby Tomlinson homered leading off the third against Kershaw, who struck out six over six innings. He allowed eight hits and two runs.

The left-hander struck out pinch-hitter Tim Federowicz to end the sixth with the bases loaded after Orlando Calixte's sacrifice fly. Kershaw is 21-9 with a 1.62 ERA in 40 career games and 39 starts against San Francisco and he improved to 7-1 in nine 2017 road starts.

Kershaw had a limit of 100 pitches in his third start since returning from a lower back strain — and he was efficient, his night done instead after 91.

Cueto (7-8) struck out eight over 3 2/3 innings, allowing four runs and six hits with four walks in his third start since coming off the disabled list.

The Dodgers elevated the right-hander's pitch count in a hurry, with Cueto throwing 77 through three. But he struck out Grandal as Los Angeles left the bases loaded and stranded runners in scoring position in each of the first three innings.

Then, the Dodgers got going in the fourth.

FREE PASSES

Bellinger was intentionally walked three times in all, making him the first Dodgers player to do so since Jose Hernandez on June 4, 2004, against Arizona.

TRAINER'S ROOM

Dodgers: Los Angeles didn't hold batting practice after the long game, so LHP Hyun-Jin Ryu threw a 48-pitch bullpen session rather than a simulated game. He had his turn skipped this series to give him a break but will start Sunday's series finale at Washington. ... OF Andre Ethier, who returned Sept. 1 after sitting out all season with a herniated disk in his back, is scheduled to start Friday against the Nationals. Roberts wants to see how Ethier holds up in a full game, "keep him going and see what we have."

Giants: Closer Mark Melancon, who joined the Giants in the offseason on a $62 million, four-year contract, had season-ending pronator surgery to solve his forearm injury. The rehab timeline is expected to be six to eight weeks, having him recovered in plenty of time to be prepared for spring training. Melancon went 1-2 with a 4.50 ERA and 11 saves in 32 appearances and 30 innings this season.

UP NEXT

RHP Yu Darvish (8-12, 4.25 ERA) will face the Giants for the first time in his career in the series finale while pitching opposite LHP Matt Moore (5-13, 5.31), who is 1-2 with a 7.01 ERA over his past five starts vs. L.A.